Skip to content

Instantly share code, notes, and snippets.

@pramodjodhani
Created May 1, 2024 06:05
Show Gist options
  • Save pramodjodhani/e8de4a93f9bec2ab55f318373d2ccf8e to your computer and use it in GitHub Desktop.
Save pramodjodhani/e8de4a93f9bec2ab55f318373d2ccf8e to your computer and use it in GitHub Desktop.
Flux checkout - disable address fields for local pickup shipping method.
<?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