I am trying to display a message in a custom page template based on the cart total using a function but it not displaying my message.
Please see function below:
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!";
}
}
You should get the subtotal when calling the cart not the total
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!";
}
}
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.