Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/231.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

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/wordpress/11.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

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/meteor/3.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 如果购物车中有4个项目,Woocommerce不会显示弹出窗口_Php_Wordpress_Woocommerce_Popup - Fatal编程技术网

Php 如果购物车中有4个项目,Woocommerce不会显示弹出窗口

Php 如果购物车中有4个项目,Woocommerce不会显示弹出窗口,php,wordpress,woocommerce,popup,Php,Wordpress,Woocommerce,Popup,我有一些工作代码,这是做一个条件如下,以触发购物车页面上的弹出窗口 如果购物车中的物品少于8件,则使用elementor显示弹出窗口 短码。 如果有8项或更多项,则使用wof_滚轮显示弹出窗口。 如果购物车中的商品数量=4,如何使其完全不显示弹出窗口 我认为通过添加if-else,而不返回任何内容,它会起作用。但是弹出窗口仍然会触发 我的代码: 您的if/else语句不起作用,因为if$items\u count

我有一些工作代码,这是做一个条件如下,以触发购物车页面上的弹出窗口

如果购物车中的物品少于8件,则使用elementor显示弹出窗口 短码。 如果有8项或更多项,则使用wof_滚轮显示弹出窗口。 如果购物车中的商品数量=4,如何使其完全不显示弹出窗口

我认为通过添加if-else,而不返回任何内容,它会起作用。但是弹出窗口仍然会触发

我的代码:


您的if/else语句不起作用,因为if$items\u count<8对于if$items\u count==4返回true。您应该先检查$items\u count==4,然后再检查$items\u count是否<8

希望这有助于:

//Shortcode Check 
function checkShortCode()
{
    $page = get_post(5);
    if (WC()->cart) {
        $items_count = WC()->cart->get_cart_contents_count();
        if ($items_count == 4) {
            return;
        } 
        if  ($items_count < 8) {
            //Remove the Default Hook function for this shortcode
            remove_shortcode('wof_wheel');
            //Add custom callback for that short to display message required
            add_shortcode('wof_wheel', 'myCustomCallBack');
        }
    }
}
add_action('wp_loaded', 'checkShortCode');

function myCustomCallBack()
{
    echo do_shortcode('[elementor-template id="3431"]');
}

实际上,您不需要else if,因为返回将停止函数其余部分的执行。

当item count为4时,第一个条件<8已经为真,因此它没有理由首先进入else if分支…将其转过来,首先检查==4。工作非常好。是的,在较大的项目之前先检查项目_count==4是有意义的。谢谢
//Shortcode Check 
function checkShortCode()
{
    $page = get_post(5);
    if (WC()->cart) {
        $items_count = WC()->cart->get_cart_contents_count();
        if ($items_count == 4) {
            return;
        } 
        if  ($items_count < 8) {
            //Remove the Default Hook function for this shortcode
            remove_shortcode('wof_wheel');
            //Add custom callback for that short to display message required
            add_shortcode('wof_wheel', 'myCustomCallBack');
        }
    }
}
add_action('wp_loaded', 'checkShortCode');

function myCustomCallBack()
{
    echo do_shortcode('[elementor-template id="3431"]');
}