WooCommerce - 在付款前设置总价

3
我在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>

现在我需要在付款前更新总价。

有什么想法吗?谢谢。

1个回答

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/


网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接