php - 如何在 Woocommerce 中根据购物车总数显示消息
问题描述
我正在尝试使用函数根据购物车总数在自定义页面模板中显示一条消息,但它不显示我的消息。
请看下面的功能:
add_shortcode( 'custom_order, 'woocommerce_order_subtotal' );
function woocommerce_order_subtotal(){
$sub = WC()->cart->total();
// if for the subtotal:
if ($sub > 100)) {
echo "Hello world!";
}
}
解决方案
调用购物车时应该得到小计而不是总数
add_shortcode( 'custom_order, 'woocommerce_order_subtotal' );
function woocommerce_order_subtotal(){
$sub = WC()->cart->total(); //this is wrong here you gettin total not subtotal
$sub = WC()->cart->subtotal
//Or this following
$sub = WC()->cart->get_cart_subtotal()
// if for the subtotal:
if ($sub > 100)) {
echo "Hello world!";
}
}
推荐阅读
- python - 如何在 Gurobi Python 目标函数中对“if”条件进行建模?
- android - Android Jetpack Navigation:键盘将导致任何导航的 Fragment 视图大小为 0
- javascript - 我需要找出我的代码中的问题,因为它给出了错误的结果(+1)
- django - 在 Django 表单中保存并继续
- flutter - DropdownButton 始终处于禁用状态
- javascript - 对象可能在 Typescript 中的字符串值“未定义”
- c++ - 引用类不能从 C++ 中的 IAudioSessionNotification 继承
- php - 扩展服务器时使用不同的时区是否会产生不利影响?
- python - 在 selenium 中使用用户数据会导致删除扩展
- arrays - 根据Excel中的条件比较数组中的两个日期