简体   繁体   中英

WooCommerce: Only show cheque payment option when custom field is used

I need the "cheque" payment option to be visable in checkout only when the "_billing_eu_vat_number" field is filled in by the customer.

The "_billing_eu_vat_number" is from the EU/UK VAT for WooCommerce plugin.

Any ideas?

I'm using a code that can help you. This code enable "cheque" payment option only for France selected billing country:

function payment_gateway_disable_country( $available_gateways ) {
    if ( is_admin() ) return $available_gateways;
    if (WC()->countries instanceof WC_Countries && !is_null(WC()->customer)){
    if ( isset( $available_gateways['cheque'] )&& WC()->customer->get_billing_country() <> 'FR' ) {
        unset( $available_gateways['cheque'] );
    }}
    return $available_gateways;
}
add_filter( 'woocommerce_available_payment_gateways', 'bbloomer_payment_gateway_disable_country' );

You can replace the "FR" by all country you want. Country code ISO 3166-1 alpha-2.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM