我可以使用 Insert a custom total row on cart and checkout totals in Woocommerce 答案代码向结帐总计表中添加额外的一行。 (虽然我需要在底部添加我的)但我找不到或弄清楚如何计算我需要的总数。
我需要添加的总数应包括除产品成本之外的所有内容(因此应包括运费、增值税、费用等)。
我无法将产品价格更改为零,因为它们用于计算费用。
我的代码尝试:
Show Modified Settings
我将如何将此添加到结帐和购物车页面?
答案 0 :(得分:2)
要在底部显示它,请改用 woocommerce_cart_totals_after_order_total
和 woocommerce_review_order_after_order_total
动作钩子。
所以你得到:
function display_custom_total() {
// Get (sub)total
$subtotal = WC()->cart->subtotal;
$total = WC()->cart->total;
// Calculate
$total_to_pay = $total - $subtotal;
// The Output
echo ' <tr class="cart-total-to-pay">
<th>' . __( 'Total to pay', 'woocommerce' ) . '</th>
<td data-title="total-to-pay">' . wc_price( $total_to_pay ) . '</td>
</tr>';
}
add_action( 'woocommerce_cart_totals_after_order_total', 'display_custom_total', 20 );
add_action( 'woocommerce_review_order_after_order_total', 'display_custom_total', 20 );
相关:Insert a custom total excluding products cost in WooCommerce order emails