Viewing 6 replies - 1 through 6 (of 6 total)
  • Same issue if I add fields via Booster for WooCommerce. Either option would be welcomed

    Actually, even the standard filters aren’t working for me. eg.:

    add_filter( 'woocommerce_checkout_fields' , 'custom_override_checkout_fields' );
    function custom_override_checkout_fields( $fields ) {
        $fields['shipping']['shipping_company']['label'] = 'Business Name';
    	$fields['billing']['billing_company']['label'] = 'Business Name';
    	     $fields['shipping']['shipping_phone'] = array(
            'label'     => __('Recipient\'s Phone', 'woocommerce'),
        'placeholder'   => _x('Phone', 'placeholder', 'woocommerce'),
        'required'  => true,
        'class'     => array('form-row-wide'),
        'clear'     => true
         );
         return $fields;
    }
    
    add_action( 'woocommerce_admin_order_data_after_shipping_address', 'my_custom_checkout_field_display_admin_order_meta', 10, 1 );
    function my_custom_checkout_field_display_admin_order_meta($order){
        echo '<p><strong>'.__('Phone From Checkout Form').':</strong> ' . get_post_meta( $order->get_id(), '_shipping_phone', true ) . '</p>';
    }

    These changes appear in checkout/meta, but not in the address book.

    Plugin Author Matt Harrison

    (@matt-h-1)

    Hi,

    Looking at that plugin it looks like it only adds fields to the checkout and not the address edit pages which is why you aren’t seeing it. You can see even without the Address Book plugin active that it doesn’t modify the fields when editing them through My Account (not sure if that is a bug in that plugin?).

    The same with your sample code, you are using the filters which only edit the checkout. To edit them in both locations you will want to use the woocommerce_billing_fields and woocommerce_shipping_fields filters as documented here: https://woocommerce.com/document/tutorial-customising-checkout-fields-using-actions-and-filters/

    Here is some sample code to do the same thing you were trying to do in your example:

    
    add_filter( 'woocommerce_billing_fields', 'custom_override_billing_fields' );
    
    function custom_override_billing_fields( $fields ) {
        $fields['billing_company']['label'] = 'Business Name';
    
        return $fields;
    }
    add_filter( 'woocommerce_shipping_fields', 'custom_override_shipping_fields' );
    
    function custom_override_shipping_fields( $fields ) {
        $fields['shipping_company']['label'] = 'Business Name';
    
        $fields['shipping_phone'] = array(
            'label'     => __('Recipient\'s Phone', 'woocommerce'),
            'placeholder'   => _x('Phone', 'placeholder', 'woocommerce'),
            'required'  => true,
            'class'     => array('form-row-wide'),
            'clear'     => true
        );
    
        return $fields;
    }
    

    Thanks Matt – will have a look through your provided sample and see how we go. I was following that exact link to create the sample that I did, under the “Adding Custom Shipping And Billing Fields” section. Because the woocommerce_billing_fields and woocommerce_shipping_fields filters are only mentioned in passing in the first section, I hadn’t realised they were critical to applying the fields throughout.

    Cheers! ??

    Plugin Author Matt Harrison

    (@matt-h-1)

    Yeah, that is a little confusing. If you use those filters it edits the fields everywhere billing and shipping addresses are used.

    The other ones it talks about only edits the actual checkout forms.

    • This reply was modified 2 years, 7 months ago by Matt Harrison.

    Makes sense once I think about it!

    Much appreciated, that worked a charm!

Viewing 6 replies - 1 through 6 (of 6 total)
  • The topic ‘Checkout Fields Manager Compatibility’ is closed to new replies.