【发布时间】:2021-08-14 10:42:59
【问题描述】:
我可以使用Insert a custom total row on cart and checkout totals in Woocommerce 答案代码在结帐总计表中添加额外的一行。 (尽管我需要在底部添加我的)但我无法找到或弄清楚如何计算我需要的总数。
我需要添加的总金额应包括除产品成本之外的所有内容(因此应包括运费、增值税、费用等)。
我无法将产品价格更改为零,因为它们用于计算费用。
我的代码尝试:
add_action( 'woocommerce_cart_totals_before_shipping', 'display_custom_total', 20 );
add_action( 'woocommerce_review_order_before_shipping', 'display_custom_total', 20 );
function display_custom_total() {
$total_to_pay = 0;
// Do something here
// The Output
echo ' <tr class="cart-total-to-pay">
<th>' . __( "Total to pay", "woocommerce" ) . '</th>
<td data-title="total-to-pay">' . number_format($total_to_pay, 2) . '</td>
</tr>';
}
如何将其添加到结帐和购物车页面?
【问题讨论】:
标签: php wordpress woocommerce cart checkout