wpmudev-sls
10/29/2017 - 8:47 AM

This MU plugin allows remove fields from Checkout page

This MU plugin allows remove fields from Checkout page

<?php
function wpmu_marketpress_remove_fields_checkout( $address_fields, $type ) {
	$cart  = MP_Cart::get_instance();
	$total = $cart->total( false );
	if ( $total == 0 ) {
		$allowed = array(
			'billing[first_name]',
			'billing[last_name]',
			'billing[email]',
			'billing[zip]',
		);
		foreach ( $address_fields as $key => $field ) {
			if ( $field['type'] == 'complex' ) {
				foreach ( $field['subfields'] as $k => $sfield ) {
					if ( ! in_array( $sfield['name'], $allowed ) ) {
						unset( $address_fields[ $key ]['subfields'][ $k ] );
						if ( empty( $address_fields[ $key ]['subfields'] ) ) {
							unset( $address_fields[ $key ] );
						}
					}
				}
				continue;
			}
			if ( ! in_array( $field['name'], $allowed ) ) {
				unset( $address_fields[ $key ] );
			}
		}
	}

    return $address_fields;
}

add_filter( 'mp_checkout/address_fields_array', 'wpmu_marketpress_remove_fields_checkout' );