• I have added/unset some account and checkout custom fields. How can I modify the woocommerce account fields in the backend user profile page?
    I tried:

    add_filter( ‘woocommerce_customer_meta_fields’ , ‘custom_override_customer_meta_fields’ );
    function custom_override_customer_meta_fields( $fields ) {
    unset($fields[‘billing’][‘billing_company’]);
    unset($fields[‘shipping’][‘shipping_company’]);
    unset($fields[‘shipping’][‘shipping_last_name’]);
    unset($fields[‘shipping’][‘shipping_address_2’]);
    unset($fields[‘shipping’][‘shipping_country’]);
    unset($fields[‘shipping’][‘shipping_state’]);

    return $fields;
    }
    … with no success :/

    Any suggestions?
    Thanks in advance! ??

    https://www.ads-software.com/plugins/woocommerce/

Viewing 1 replies (of 1 total)
  • Hi, you pointing at the wrong element in the array. It should be

    unset($fields[‘shipping’][‘fields’][‘shipping_last_name’]);

    I’m adding another field under the shipping address and sorting the order.

    add_filter( 'woocommerce_customer_meta_fields' , 'sort_shipping' );
    
    function sort_shipping( $fields ) {
    
        // temporary store existing array elements
        $f = $fields['shipping']['fields'];
        $shipping_first_name = $f['shipping_first_name'];
        $shipping_last_name = $f['shipping_last_name'];
        $shipping_company = $f['shipping_company'];
        $shipping_address_1 = $f['shipping_address_1'];
        $shipping_address_2 = $f['shipping_address_2'];
        $shipping_city = $f['shipping_city'];
        $shipping_postcode = $f['shipping_postcode'];
        $shipping_country = $f['shipping_country'];
        $shipping_state = $f['shipping_state'];
    
        // reassign elements in the shipping array
        $fields['shipping']['fields'] = array(
            'shipping_first_name' => $shipping_first_name,
            'shipping_last_name' => $shipping_last_name,
            'shipping_company' => $shipping_company,
            'shipping_attn' => array(
                'label' => 'Attention To',
                'description' => ''
            ),
            'shipping_address_1' => $shipping_address_1,
            'shipping_address_2' => $shipping_address_2,
            'shipping_city' => $shipping_city,
            'shipping_postcode' => $shipping_postcode,
            'shipping_country' => $shipping_country,
            'shipping_state' => $shipping_state,
        );
    
        return $fields;
    }
Viewing 1 replies (of 1 total)
  • The topic ‘Adding/Deleting a custom user profile field’ is closed to new replies.