【问题标题】:Woocommerce - Hide payment based on selected shipping methodWoocommerce - 根据选定的运输方式隐藏付款
【发布时间】:2014-08-06 04:16:02
【问题描述】:

我一直在尝试找出如何根据选定的运费隐藏某些支付网关。我一直在使用这段代码,但到目前为止还没有。有什么帮助吗?

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' );

}
}

【问题讨论】:

    标签: methods woocommerce payment shipping gateway


    【解决方案1】:
    //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' );
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2018-11-09
      • 2016-04-13
      • 1970-01-01
      • 1970-01-01
      • 2018-10-28
      • 2019-01-16
      • 2018-03-01
      相关资源
      最近更新 更多