【问题标题】:Hide cash on delievery for orders over certain amount of money in woocommerce在woocommerce中隐藏超过一定金额的订单的货到付款
【发布时间】:2014-11-23 22:01:54
【问题描述】:

我希望只有价格低于 100 美元的货到付款选项,并在购物车高于 100 美元时自动隐藏它。问题是,我现在有 3 种不同的付款方式。贝宝、支票和 COD。当一个人购买东西并选择货到付款方式时,我在那里写了一个描述,说“如果您的订单低于 100 美元,您可以选择 COD”。但是有些人忽略了它,即使他们的购买超过 100 美元,仍然选择 COD。所以,我想在购买超过 100 美元时自动隐藏 COD。因此,当购买超过 100 美元时,只有两种选择,Paypal 和 Cheque。 希望我能再澄清一点。

谢谢

【问题讨论】:

    标签: php wordpress woocommerce


    【解决方案1】:

    您可以使用 woocommerce_available_payment_gateways 挂钩来编辑 woocommerce 网关。

    add_filter( 'woocommerce_available_payment_gateways' , 'change_payment_gateway', 20, 1);
    
    /**
     * remove cod gateway if cart total > 100
     * @param $gateways
     * @return mixed
     */
    function change_payment_gateway( $gateways ){
        // Compare cart subtotal (without shipment fees)
        if( WC()->cart->subtotal > 100 ){
             // then unset the 'cod' key (cod is the unique id of COD Gateway)
             unset( $gateways['cod'] );
        }
        return $gateways;
    }
    

    【讨论】:

    • 可以用更多的解释
    • @XcID 太好了,它确实成功了。我将那段代码添加到我的主题的 function.php 文件中,就像一个魅力。非常感谢。
    • 别忘了检查答案
    【解决方案2】:
    add_filter( 'woocommerce_available_payment_gateways' , 'hide_payment_gateway', 20, 1);
            
    function hide_payment_gateway( $gateways ){
          //change whatever amount you want
          if( WC()->cart->subtotal < 699 ){
          // then unset the 'cod' key (cod is the unique id of COD Gateway)
          unset( $gateways['cod'] );
          add_action( 'woocommerce_review_order_before_payment', 'COD_exceed_amount_before_paying_notice' );
          }
          return $gateways;
    }
    
    function COD_exceed_amount_before_paying_notice() {
          wc_print_notice( __( 'COD option not available on orders below 699.00', 'woocommerce' ), 'notice' );
    }
    

    【讨论】:

      猜你喜欢
      • 2020-04-04
      • 2017-05-31
      • 2016-10-16
      • 2019-04-25
      • 2016-04-13
      • 2021-02-21
      • 1970-01-01
      • 2021-01-26
      • 1970-01-01
      相关资源
      最近更新 更多