0

I'm creating a store in magento 1.7.0.2

Courses are virtual products that can be bought. When buying you sign up for a course.

One customer can buy courses for other people. I've set a custom option, text field, for a product where the customer is supposed to write the name of the person attending the course.

In most cases the customer buys the course for himself so I want the custom option to have a default value which is the customers name (if signed in).

I want this to be visible when the customer is viewing the product so that he can change it if needed.

How can this be done?

1

I know this is not the right way to do it, But it will work in your case.

First create a custom option ie: Text Field. Now using firebug note the id of that field. In my case it was options_2_text.

Now goto template/catalog/product/view.phtml and place this code

<script type="text/javascript">
    $field = document.getElementById('options_2_text');
    $field.value = "<?php if(Mage::getSingleton('customer/session')->isLoggedIn()){
    $customer = Mage::getSingleton('customer/session')->getCustomer();
    $name = $customer->getName();
    echo $name;
} ?>";
</script>

Here on first line $field = document.getElementById('options_2_text'); instead of options_2_text you should put the id which you noted from firebug.

| improve this answer | |
  • Thanks Dexter. This'll work on a certain field. I have these (same) fields in several products but since in each product they're custom options they're all given a different ID.. too many of them... – user2612498 Aug 28 '13 at 9:27
  • I am sorry i haven't tried it. Let me know if you get it working – Dexter Aug 29 '13 at 4:29

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.