i have two classes of product. i want to use "add to cart" button on real product contents. and wants to use "register" text on other content and "submit" button for third content. but control will go to cart page in all case (as usual).
Hi drupalmind,
I actually needed some similar functionality for my site. I found the option to change ALL the 'Add to Cart' buttons but obviously this wasn't good enough.
Here is how I tackled the problem (as Im fairly new to drupal and dont know how to create modules yet)
- Created a node-product.tpl.php file in my template directory to override the default behavior for product nodes.
- In this file checked to see what class of product we were looking at
- After determining what class of product it was I used a case statement/if else to change the value of the 'Add to cart' form using string replace. Something like below:
if ($class == 'your_class')
{
echo str_replace('Add to Cart', 'Register', $node->content['add_to_cart']["#value"]);
}
else
{
echo $node->content['add_to_cart']["#value"];
}It isn't very elegant but it works until my skills improve enough to figure out how to write a module for this 
Hope this helps
It is overriding all the content except the "add to cart" button text.
when i use the code all the text disappear and button show up with text "add to cart" but there would be "register"
So you just would want to override the "add to cart" text on the button on node pages?
You could try something like:
<?php
function my_module_form_alter($form_id, &$form) {
// Normally a switch is used because you may want to alter more than
// one form and it is easy to add a new case for each form.
// $output .= dsm($form);
switch ($form_id) {
// This is our form ID.
case 'product_node_form':
$form['submit']['#title'] = t('register');
break;
case 'other_node_form':
$form['submit']['#title'] = t('other');
break;
}
}
?>Use a hook_form_alter to change forms that already exist. This should be in a new module.
Install the devel module and uncomment the "$output .= dsm($form);" part and see which exact name the $form['submit']['#title'] has and so how to change it.
Good luck!
I have made a module to alter the form but i have not got the solution may be i have not got the $node->type or some thing else problem. or i have not got $form['submit']['#title'] it correctly, any how i have tried a couple of methods but problem is still there.
Did you install and enable the Devel module?
And ucomment:
<?php
$output .= dsm($form);
?>The title for the submit button should be there, dito the form ID stuff. I didn't work with classes before, so I don't know if the form_id will change. You could use node->type or something instead.
work on the hook alter of uc_product module have worked for me.
i m also pasting a code snap that works for me
$content_type = $form['#parameters'][2]->type;
$uc_form_id = $form_id;
$uc_form_id = explode("_",$uc_form_id);
array_pop($uc_form_id);
$uc_form_id = implode("_", $uc_form_id);
if(($uc_form_id == "uc_product_add_to_cart_form") and ($content_type=="committee_events")){
$form['submit']['#value'] = t('Register');
}
else if(($uc_form_id == "uc_product_add_to_cart_form") and ($content_type=="product")){
$form['submit']['#value'] = t('Add to cart');
}Thx for the contribution of all participants here!
in form alter of uc_product page.
Thanks in advance!
Nice snippet! Thanks a lot!
I just want to add that the code given in #3 works great, except that I had to change 'title' to 'value' for it to work.
Thanks a lot for this, it has saved me some time!
Thanks for this discussion. it helped me a log... but i had to make some changes for this to work for me. Below is my module code:
function other_add_to_cart_text_form_alter(&$form, &$form_state, $form_id) {
// Normally a switch is used because you may want to alter more than
// one form and it is easy to add a new case for each form.
// $output .= dsm($form);
// $output .= dsm($form_id);
switch ($form_id) {
// This is our form ID.
case 'uc_product_add_to_cart_form_23':
$form['submit']['#value'] = t('Continue to enter custom info');
break;
}
}
I've written a module to do this; http://drupal.org/project/uc_product_cta
