Woocommerce - 根据选定的送货方式隐藏付款

时间:2014-06-16 10:49:59

标签: methods woocommerce payment shipping gateway

我一直在努力找出如何根据选定的运费隐藏某些支付网关。到目前为止,我一直在处理这段代码。对此有何帮助?

add_action( 'woocommerce_after_checkout_form','woocommerce_custom_surcharge' );
function woocommerce_custom_surcharge() {
global $woocommerce;

 $chosen_methods = WC()->session->get( 'chosen_shipping_methods' );
 $chosen_shipping = $chosen_methods[0];

 if ($chosen_shipping == 'table_rate') {   


        function payment_gateway_disable_country( $available_gateways ) {

    unset(  $available_gateways['paytrail'] );

return $available_gateways;
}
add_filter( 'woocommerce_available_payment_gateways', 'payment_gateway_disable_country' );

}
}

1 个答案:

答案 0 :(得分:0)

//Hide payment gateways based on shipping method
function payment_gateway_disable( $available_gateways ) {
    global $woocommerce;
    $chosen_methods = WC()->session->get( 'chosen_shipping_methods' );
    $chosen_shipping = $chosen_methods[0];

    if( $chosen_shipping == 'table_rate' ) {
        unset($available_gateways['paytrail']);
    }

    return $available_gateways;
}
add_filter( 'woocommerce_available_payment_gateways', 'payment_gateway_disable' );