如何在Woocommerce中基于购物车总数显示消息

时间:2019-10-17 11:22:40

标签: 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!";
    }
}

1 个答案:

答案 0 :(得分:0)

致电购物车时应该得到小计,而不是总数

   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!";
    }
   }