【发布时间】:2018-09-27 07:35:27
【问题描述】:
我得到了with some code 的热心帮助,帮助我添加了附加到每个产品的自定义字段的组合值——在这种情况下,整个订单的体积以 m3 为单位。
我想在感谢页面的产品列表下面的表格中显示 m3 体积 - 有谁知道我应该使用的钩子。下面是显示我在购物车和结帐页面上的总交易量的代码。
add_action( 'woocommerce_cart_totals_before_shipping',
'display_cart_volume_total', 20 );
add_action( 'woocommerce_review_order_before_shipping',
'display_cart_volume_total', 20 );
function display_cart_volume_total() {
$total_volume = 0;
// Loop through cart items and calculate total volume
foreach( WC()->cart->get_cart() as $cart_item ){
$product_volume = (float) get_post_meta( $cart_item['product_id'],
'_item_volume', true );
$total_volume += $product_volume * $cart_item['quantity'];
}
if( $total_volume > 0 ){
// The Output
echo ' <tr class="cart-total-volume">
<th>' . __( "Total Shipping Volume", "woocommerce" ) . '</th>
<td data-title="total-volume">' . number_format($total_volume, 2) .
' m3</td>
</tr>';
}
}
【问题讨论】:
标签: php wordpress woocommerce custom-fields orders