在 Woocommerce 中显示购物车总运输量值 [英] Display total cart shipping volume value in Woocommerce
问题描述
我为订购家具集装箱的批发客户使用 woocommerce - 通常为 40 英尺集装箱,容积为 68 立方米.
I use woocommerce for wholesale customers who order containers of furniture - normally 40 foot containers with a volume of 68 cubic meters.
有没有办法可以在网站上的某个地方显示——也许在标题区域有一个框,显示他们购物篮中产品的总立方米?当他们达到 68 立方米时,我需要向客户展示,以便他们知道他们已经装满了一个容器.
Is there a way I can show somewhere on the website - maybe in the header area a box with showing the total m3 of products in their basket? I need to show the client when they reach 68m3 so they know they have filled a container.
如果客户尝试提交小于 68 立方米的订单,是否有一种方法可以闪现一条消息,向他们表明他们的容器中还有剩余空间?
And is there a way to flash up a message if a client tries to submit an order less than 68m3 indicating to them that they still have room left in their container?
感谢任何帮助.
推荐答案
你可以试试这样的:
<?php
global $woocommerce;
$items = $woocommerce->cart->get_cart();
$cart_prods_m3 = array();
//LOOP ALL THE PRODUCTS IN THE CART
foreach($items as $item => $values) {
$_product = wc_get_product( $values['data']->get_id());
//GET GET PRODUCT M3
$prod_m3 = $_product->get_length() *
$_product->get_width() *
$_product->get_height();
//MULTIPLY BY THE CART ITEM QUANTITY
//DIVIDE BY 1000000 (ONE MILLION) IF ENTERING THE SIZE IN CENTIMETERS
$prod_m3 = ($prod_m3 * $values['quantity']) / 1000000;
//PUSH RESULT TO ARRAY
array_push($cart_prods_m3, $prod_m3);
}
echo "Total of M3 in the cart: " . array_sum($cart_prods_m3);
?>
参见 WC() 文档:https://docs.woocommerce.com/document/类引用/
See WC() docs: https://docs.woocommerce.com/document/class-reference/
这篇关于在 Woocommerce 中显示购物车总运输量值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!