Last active
August 4, 2022 17:30
-
-
Save luizbills/c062a6007a6b4b8dcd9df0d698cbab46 to your computer and use it in GitHub Desktop.
Desativar pagamento quando a opção de frete "Retirar no local" for escolhida
This file contains hidden or 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 | |
add_filter( 'woocommerce_available_payment_gateways', 'lpb_remove_other_payment_options_for_local_pickup' ); | |
function lpb_remove_other_payment_options_for_local_pickup ( $gateways ) { | |
$chosen_shipping_rates = WC()->session->get( 'chosen_shipping_methods' ); | |
if ( ! empty( $chosen_shipping_rates ) && strpos( $chosen_shipping_rates[0], 'local_pickup' ) !== false ) { | |
// disable payment | |
add_filter( 'woocommerce_cart_needs_payment', '__return_false' ); | |
// remove all payment gateways | |
return array(); | |
} | |
return $gateways; | |
} | |
add_action('woocommerce_checkout_process', 'lpb_disable_payment_for_local_pickup'); | |
function lpb_disable_payment_for_local_pickup () { | |
$chosen_shipping_rates = WC()->session->get( 'chosen_shipping_methods' ); | |
if ( ! empty( $chosen_shipping_rates ) && strpos( $chosen_shipping_rates[0], 'local_pickup' ) !== false ) { | |
// disable payment | |
add_filter( 'woocommerce_cart_needs_payment', '__return_false' ); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment