我在review-order.php中通过php添加费用:
<?php
global $woocommerce;
$total = number_format($woocommerce->cart->total, 2, '.', ' ');
$total = (float) number_format($total, 2, '.', ' ') + (float) number_format($vvk, 2, '.', ' ');
$total = number_format($total, 2, ',', ' ');
?>
<tr class="order-total">
<th><?php _e( 'Total', 'woocommerce' ); ?></th>
<td data-title="<?php _e( 'Total', 'woocommerce' ); ?>">
<?php echo "<strong><span class=\"amount\">€".$total."</span></strong>"; ?>
</td>
</tr>
现在我需要在付款前更新总价格。
有什么想法吗?感谢。
答案 0 :(得分:2)
我不确定我会以这种方式做事 - 下一次更新可能会让你的改变一扫而空。也许相反,使用费用API添加您的费用并将代码添加到您的functions.php或相关代码文件中。
在下面的示例中,添加了1%的附加费(您可以轻松修改它以满足您的需求):
add_action('woocommerce_cart_calculate_fees','woocommerce_custom_surcharge' );
function woocommerce_custom_surcharge() {
global $woocommerce;
if ( is_admin() && ! defined( 'DOING_AJAX' ) )
return;
$percentage = 0.01;
$surcharge = ( $woocommerce->cart->cart_contents_total + $woocommerce->cart->shipping_total ) * $percentage;
$woocommerce->cart->add_fee( 'Surcharge', $surcharge, true, '' );
}
https://docs.woothemes.com/document/add-a-surcharge-to-cart-and-checkout-uses-fees-api/