[MARKETPRESS] hide some fields on checkout page

I would like to remove a few fields that are not needed on the checkout page but those are required.

town/city
country

During the chat, we were able to hide the Company filed via CSS.

  • Ash
    • WordPress Hacker

    Hello Dwight

    Please try the following code:

    add_filter( 'mp_checkout/address_fields_array', function( $address_fields, $type ){
    	if ( 'billing' == $type ) {
    		foreach ( $address_fields as $key => $address_field ) {
    			if ( isset( $address_field['subfields'] ) ) {
    				foreach ( $address_field['subfields'] as $subfield_key => $subfield ) {
    					if ( isset( $subfield['name'] ) && 'billing[zip]' == $subfield['name'] ) {
    							unset( $address_fields[$key]['subfields'][$subfield_key] );
    					}
    
    					if ( isset( $subfield['name'] ) && 'billing[state]' == $subfield['name'] ) {
    							unset( $address_fields[$key]['subfields'][$subfield_key] );
    					}
    				}
    			}
    			if ( isset( $address_field['name'] ) && 'billing[city]' == $address_field['name'] ) {
    					unset( $address_fields[$key] );
    			}
    			if ( isset( $address_field['name'] ) && 'billing[country]' == $address_field['name'] ) {
    					unset( $address_fields[$key] );
    			}
    		}
    	}
    
    	return $address_fields;
    }, 20, 2 );

    You can use this code in your child theme's functions.php if the theme is not changed. Otherwise mu-plugin is the best option. To create a mu-plugin, go to wp-content/mu-plugins folder. If there is no mu-plugins folder then, create one. Now, inside the mu-plugins folder create file with name anything.php (make sure file extension is .php). Now start with a <?php tag and then put the above code.

    Hope it helps! Please feel free to ask more questions if you have any.

    Have a nice day!

    Cheers,
    Ash

Thank NAME, for their help.

Let NAME know exactly why they deserved these points.

Gift a custom amount of points.