I want the client to use the Woocommer cart function, but I don’t need the checkout and stuff.
So I made this page and put a form with the cart list.
But I don’t know how to embed the CART list in the email.
I tried the code below to fetch the cart list, but the shortcode {{cart_items}} doesn’t work as planned.
function get_cart_items() {
global $woocommerce;
$cart_items = $woocommerce->cart->get_cart();
$products_info = '';
foreach ($cart_items as $cart_item) {
$product = $cart_item['data'];
$products_info .= $product->get_name() . ' - 数量: ' . $cart_item['quantity'] . "<br>";
}
return $products_info ? $products_info : '购物车为空';
}
add_filter('bricks/template_variable', function($variables) {
$variables['cart_items'] = get_cart_items();
return $variables;
});