Created
May 1, 2024 06:05
-
-
Save pramodjodhani/e8de4a93f9bec2ab55f318373d2ccf8e to your computer and use it in GitHub Desktop.
Flux checkout - disable address fields for local pickup shipping method.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/** | |
* Flux checkout - disable address fields for local pickup shipping method. | |
* | |
* @return void | |
*/ | |
function flux_disable_fields_for_local_pickup() { | |
$wc_ajax = filter_input( INPUT_GET, 'wc-ajax' ); | |
if ( ! Iconic_Flux_Core::is_checkout( true ) && 'checkout' !== $wc_ajax ) { | |
return; | |
} | |
$chosen_methods = WC()->session->get( 'chosen_shipping_methods' ); | |
if ( empty( $chosen_methods[0] ) ) { | |
return; | |
} | |
if ( false === strpos( $chosen_methods[0], 'local_pickup' ) ) { | |
return; | |
} | |
// Remove address step. | |
add_filter( | |
'flux_custom_steps', | |
function( $steps ) { | |
unset( $steps[1] ); | |
return array_values( $steps ); | |
} | |
); | |
// Move state, postcode and country to details step. | |
add_filter( | |
'flux_checkout_details_fields', | |
function( $details_fields ) { | |
return array_merge( $details_fields, array( 'billing_state', 'billing_postcode', 'billing_country' ) ); | |
} | |
); | |
// Remove fields. | |
add_filter( | |
'woocommerce_checkout_fields', | |
function( $fields ) { | |
unset( $fields['billing']['billing_street_number'] ); | |
unset( $fields['billing']['billing_company'] ); | |
unset( $fields['billing']['billing_address_1'] ); | |
unset( $fields['billing']['billing_address_2'] ); | |
unset( $fields['billing']['billing_city'] ); | |
unset( $fields['billing']['billing_phone'] ); | |
unset( $fields['order']['order_comments'] ); | |
return $fields; | |
}, | |
101 | |
); | |
} | |
add_action( 'init', 'flux_disable_fields_for_local_pickup' ); | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment