• Resolved promoteyou

    (@promoteyou)


    I’m trying to update the label on the billing_phone field using the following code snippet:

    // Hook in
    add_filter( 'woocommerce_checkout_fields' , 'custom_override_checkout_fields' );
    
    // Our hooked in function - $fields is passed via the filter!
    function custom_override_checkout_fields($fields) {
         $fields['billing']['billing_phone']['label'] = 'Phone (10 digits only - i.e. 216555111) ';
         return $fields;
    }

    I’ve gotten the base code here from a couple WooCommerce sources (this is one: https://woocommerce.com/posts/customize-checkout-fields-woocommerce/) so I’m pretty sure my hooks are correct. But when I try to Save & Activate this snippet I get the error:

    The snippet has been deactivated due to an error on line 6:
    
    Cannot redeclare function custom_override_checkout_fields.

    (line 6 is the line beginning $fields in the function)

    The page I need help with: [log in to see the link]

Viewing 2 replies - 1 through 2 (of 2 total)
  • Plugin Author Shea Bunge

    (@bungeshea)

    It looks like you might already have a function with that name running on your site.

    I always recommend using anonymous functions where possible:

    // Hook in
    add_filter( 'woocommerce_checkout_fields', function ($fields) {
         $fields['billing']['billing_phone']['label'] = 'Phone (10 digits only - i.e. 216555111) ';
         return $fields;
    } );
    Thread Starter promoteyou

    (@promoteyou)

    Thanks! That did indeed solve my issue! Leave it to a lay person to not understanding that trying to call/declare the same function in multiple snippets wouldn’t work. Marking this as solved!

Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘Error in snippet to update checkout label’ is closed to new replies.