php - Woocommerce Payment Gateway Based Checkout Fields -


i looking remove checkout fields based on payment gateway selected.

i have added following code in function.php, not working. problem facing is, going in if condition, unset not working inside if condition. when tried echo inside if condition, showing in browser.

add_filter( 'woocommerce_checkout_fields' , 'custom_override_checkout_fields' ); function custom_override_checkout_fields( $fields ) {      if($_post['payment_method'] === "wcwcpdpg"){         echo "this";        unset($fields['billing']['billing_first_name']);        unset($fields['billing']['billing_last_name']);        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_postcode']);        unset($fields['billing']['billing_country']);        unset($fields['billing']['billing_state']);        unset($fields['billing']['billing_phone']);        unset($fields['order']['order_comments']);        unset($fields['billing']['billing_email']);        unset($fields['account']['account_username']);        unset($fields['account']['account_password']);        unset($fields['account']['account_password-2']);     }      return $fields; } 

when remove if condition, fields unset, however, want unset specific payment gateway only.

any appreciated :)

try

if (wc()->session->chosen_payment_method == "wcwcpdpg") {

instead of

if($_post['payment_method'] === "wcwcpdpg"){

then add child theme's functions.php filter applied each time payment gateway toggled:

function filter_woocommerce_update_order_review_fragments( $array ) {     ob_start();    wc_get_template( 'checkout/form-billing.php', array( 'checkout' => wc()->checkout() ) );     $array[".woocommerce-billing-fields"] = ob_get_clean();    return $array;  };   add_filter( 'woocommerce_update_order_review_fragments', 'filter_woocommerce_update_order_review_fragments', 10, 1 ) 

i suspect there's better way this, it's first attempt. please post update here if have better solution.


Comments

Popular posts from this blog

toolbar - How to add link to user registration inside toobar in admin joomla 3 custom component -

linux - disk space limitation when creating war file -