Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/wordpress/12.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php 最低购物车金额,WooCommerce中特定产品除外_Php_Wordpress_Woocommerce_Cart_Hook Woocommerce - Fatal编程技术网

Php 最低购物车金额,WooCommerce中特定产品除外

Php 最低购物车金额,WooCommerce中特定产品除外,php,wordpress,woocommerce,cart,hook-woocommerce,Php,Wordpress,Woocommerce,Cart,Hook Woocommerce,在我的网站上,我只允许最低价值为15欧元的订单,但想对一种产品破例。如果有人知道如何在这方面帮助我,我将不胜感激。最小订单值的编码如下所示。有人知道我如何通过产品ID调整此项以排除一个产品吗 add_action( 'woocommerce_check_cart_items', 'wc_set_min_total' ); function wc_set_min_total() { if( is_cart() || is_checkout() ) { global $wo

在我的网站上,我只允许最低价值为15欧元的订单,但想对一种产品破例。如果有人知道如何在这方面帮助我,我将不胜感激。最小订单值的编码如下所示。有人知道我如何通过产品ID调整此项以排除一个产品吗

add_action( 'woocommerce_check_cart_items', 'wc_set_min_total' );
function wc_set_min_total() {

    if( is_cart() || is_checkout() ) {
        global $woocommerce;

        // Setting the minimum cart total
        $minimum_cart_total = 15;

        $total = WC()->cart->subtotal;


        if( $total <= $minimum_cart_total  ) {

            wc_add_notice( sprintf( '<strong>A Minimum of %s %s is required before checking out.</strong>'
                .'<br />Current cart\'s total: %s %s',
                $minimum_cart_total,
                get_option( 'woocommerce_currency'),
                $total,
                get_option( 'woocommerce_currency') ),
            'error' );
        }
    }
}
add_action('woocommerce_check_cart_items'、'wc_set_min_total');
函数wc_set_min_total(){
if(is_cart()| | is_checkout()){
全球商业;
//设置最小购物车总数
$minimum_cart_total=15;
$total=WC()->购物车->小计;

如果($total已更新-以下代码将避免在定义的最低购物车金额下结账,定义产品ID除外:

add_action( 'woocommerce_check_cart_items', 'min_cart_amount' );
function min_cart_amount() {
    ## ----- Your Settings below ----- ##

    $min_amount = 15; // Minimum cart amount
    $except_ids = array(37, 53); // Except for this product(s) ID(s)

    // Loop though cart items searching for the defined product
    foreach( WC()->cart->get_cart() as $cart_item ){
        if( in_array( $cart_item['variation_id'], $except_ids ) 
        ||  in_array( $cart_item['product_id'], $except_ids )
            return; // Exit if the defined product is in cart
    }

    if( WC()->cart->subtotal < $min_amount ) {
        wc_add_notice( sprintf(
            __( "<strong>A Minimum of %s is required before checking out.</strong><br>The current cart's total is %s" ),
            wc_price( $min_amount ),
            wc_price( WC()->cart->subtotal )
        ), 'error' );
    }
}
add_action('woocommerce_check_cart_items'、'min_cart_amount');
函数min\u cart\u amount(){
##-----您在下面的设置------##
$min_amount=15;//最小购物车金额
$except_ID=array(37,53);//此产品ID除外
//循环搜索已定义产品的购物车项目
foreach(WC()->cart->get_cart()作为$cart_项目){
if(在数组($cart\u item['variation\u id'])中,$except\u id)
||在数组中($cart\u item['product\u id',$except\u id)
return;//如果定义的产品在购物车中,则退出
}
如果(WC()->购物车->小计<$min\u金额){
wc_添加_通知(sprintf(
__(“退房前至少需要%s。
当前购物车的总数为%s”), wc_价格(最低金额), wc_价格(wc()->购物车->小计) )“错误”); } }
代码放在活动子主题(或活动主题)的functions.php文件中。已测试并运行


这很好,但在某个地方出现了一个错误(在代码段中加载了它并给出了一个php警告)。@Dav334是的,只是在
wc_price(wc()->cart->subtotal)中缺少一个收尾栏。