【发布时间】:2019-01-08 12:01:12
【问题描述】:
我有一些工作代码正在执行以下条件以触发购物车页面上的弹出窗口...
- 如果购物车中的商品少于 8 件,则显示带有
elementor shortcode的弹出窗口。 - 如果有 8 个或更多项目,则显示带有
wof_wheel的弹出窗口。
如果购物车中的商品数量 == 4,我怎样才能让它完全不显示弹出窗口?
我认为通过添加一个 if else,并且不返回任何内容,它会起作用。但弹出窗口仍然会触发。
我的代码:
//Shortcode Check
function checkShortCode()
{
$page = get_post(5);
if (WC()->cart) {
$items_count = WC()->cart->get_cart_contents_count();
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');
}else if ($items_count == 4) {
return; //Here I am trying to return nothing...
}
}
}
add_action('wp_loaded', 'checkShortCode');
function myCustomCallBack()
{
echo do_shortcode('[elementor-template id="3431"]');
}
【问题讨论】:
-
当项数为4时,第一个条件
标签: php wordpress woocommerce popup