Woocomnerce在继续结账前限制购买价值

时间:2018-01-04 作者:Mohamed Badawy

我们正在使用woocommerce,我们需要将订单总价限制在15 KD以上。

如果客户在购物车中添加了物品,而总价低于15,则无法继续结帐。

1 个回复
SO网友:Jignesh Patel

将此代码放在当前主题函数中。php文件。

方法1:

add_action( \'woocommerce_check_cart_items\', \'spyr_set_weight_requirements\' );
function spyr_set_weight_requirements() {
    if( is_cart() || is_checkout() ) {
        global $woocommerce;
        $total = WC()->cart->total;
        if( $total < 15 ){
        wc_add_notice( \'<strong>MAXIMUM CART PRICE 15 FOR CHECKOUT</strong>\',\'error\');
        }
    }
}
方法:2

function disable_checkout_button_no_shipping() {
    $total = WC()->cart->total;

    if( $total < 15 ){
        remove_action( \'woocommerce_proceed_to_checkout\', \'woocommerce_button_proceed_to_checkout\', 20 );
        echo \'<a href="#" class="checkout-button button alt wc-forward">Proceed to checkout</a>\';

    }  
}
add_action( \'woocommerce_proceed_to_checkout\', \'disable_checkout_button_no_shipping\', 1 );

In First method page redirect checkout but display only message.

方法3:

function disable_checkout_button_no_shipping() {
    $total = WC()->cart->total;

    if( $total < 15 ){
        remove_action( \'woocommerce_proceed_to_checkout\', \'woocommerce_button_proceed_to_checkout\', 20 );

    }  
}
add_action( \'woocommerce_proceed_to_checkout\', \'disable_checkout_button_no_shipping\', 99 );  

结束

相关推荐