How to replace all Add To Cart buttons with alternative text in Ubercart for anonymous users? I need to display the standard Add to Cart button for all logged in users, but anonymous users should instead see text and a link asking them to create an account or login in order to be able to add to cart. The code below works great, but it is applicable to individually-specific products only; I need it to apply to all products site-wide. How would I modify this code to accomplish this, given the fact that all Ubercart add to cart buttons contain the node ID and are thus all unique? the example shows the code applying to the product with node ID "3".

function uc_disable_cart_button_for_anonymous_form_alter(&amp;$form, &amp;$form_state, $form_id) {
    switch ($form_id) {
        case 'uc_product_add_to_cart_form_3':
        // hide add to cart button for anonymous users and show text
        if(!user_is_logged_in()) {
            unset($form['actions']['submit']);
            drupal_set_message('Please &lt;a href="/user/login"&gt;login&lt;/a&gt; or &lt;a href="/user/register"&gt;create a free Member account&lt;/a&gt; in order to proceed.');
            $form['html_markup'] = array('#markup' =&gt; t('&lt;div class="login-to-buy"&gt;Please &lt;a href="/user/login"&gt;login&lt;/a&gt; or &lt;a href="/user/register"&gt;create a free Member account&lt;/a&gt; in order to proceed.&lt;/div&gt;'));
        }
        if(user_is_logged_in()) {
            $form['actions']['submit']['#value'] = 'Add to Order';
            $form['actions']['submit']['#prefix'] = '&lt;div id="form-button-wrapper"&gt;';
            $form['actions']['submit']['#suffix'] = '&lt;/div&gt;';
        }
        break;
    }
}


Thanks!
I think I've got the solution. Any feedback would be greatly appreciated.

&lt;?php
function uc_disable_cart_button_for_anonymous_form_alter(&amp;$form, &amp;$form_state, $form_id) {
    /* Overrides the Add to Cart form text*/
    if ( !empty($form['nid']) ) {
      $node = $form['nid']['#value'];
    }
    else {
      $node = 0;
    }
    switch ($form_id) {
        case (($form_id == 'uc_product_add_to_cart_form_'.$node)):
        // hide add to cart button for anonymous users and show text
        if(!user_is_logged_in()) {
            unset($form['actions']['submit']);
            $form['html_markup'] = array('#markup' =&gt; t('&lt;div class="login-to-buy"&gt;Please login or apply for a Member account in order to proceed.&lt;br&gt;&lt;br&gt;&lt;a href="/user/login" class="btn"&gt;Log In&lt;/a&gt; &amp;nbsp; &lt;a href="/user/register" class="btn"&gt;Apply for Member account&lt;/a&gt;&lt;/div&gt;'));
        }
        if(user_is_logged_in()) {
            $form['actions']['submit']['#value'] = 'Add to Order';
            $form['actions']['submit']['#prefix'] = '&lt;div id="form-button-wrapper"&gt;';
            $form['actions']['submit']['#suffix'] = '&lt;/div&gt;';
        }
        break;
    }

    /* Overrides the Buy It Now form text*/
    if ( !empty($form['nid']) ) {
      $node = $form['nid']['#value'];
    }
    else {
      $node = 0;
    }
    switch ($form_id) {
        case (($form_id == 'uc_catalog_buy_it_now_form_'.$node)):
        // hide buy it now button for anonymous users and show text
        if(!user_is_logged_in()) {
            unset($form['actions']['submit']);
            $form['html_markup'] = array('#markup' =&gt; t('&lt;div class="login-to-buy"&gt;Please login or apply for a Member account in order to proceed.&lt;br&gt;&lt;br&gt;&lt;a href="/user/login" class="btn"&gt;Log In&lt;/a&gt; &amp;nbsp; &lt;a href="/user/register" class="btn"&gt;Apply for Member account&lt;/a&gt;&lt;/div&gt;'));
        }
        if(user_is_logged_in()) {
            $form['actions']['submit']['#value'] = 'Add to Order';
            $form['actions']['submit']['#prefix'] = '&lt;div id="form-button-wrapper"&gt;';
            $form['actions']['submit']['#suffix'] = '&lt;/div&gt;';
        }
        break;
    }
}


The main drawback that I see is that the quantity and attribute fields are still displayed, but that could be good or bad based on use-case. I'd prefer to hide them, so I may try to figure that out.