Hide cash on delievery for orders over certain amount of money in woocommerce

后端 未结 1 1242
再見小時候
再見小時候 2021-01-25 12:45

I want to have the cash on delivery option only for price below 100$ and hide it automatically when cart is above 100$. The problem is that, I have 3 different payment methods r

1条回答
  •  醉梦人生
    2021-01-25 13:17

    You can use the woocommerce_available_payment_gateways hook to edit woocommerce gateways.

    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;
    }
    

    0 讨论(0)
提交回复
热议问题