【问题标题】:Woocommerce additional price (woocommerce_before_calculate_totals) is not adding during payment付款期间未添加 Woocommerce 附加价格 (woocommerce_before_calculate_totals)
【发布时间】:2017-11-02 06:09:05
【问题描述】:

在我的应用程序中,如果客户需要某些服务,则需要为每个产品添加额外价格,因此我使用 woocommerce_before_calculate_totals 挂钩将会话中的价格(额外价格)添加到每个产品中,只要总数为显示包括我的额外价格。

但在付款时不会添加额外的价格,只会将产品原价发送到支付网关,否则在所有地方,如(购物车/结帐显示正确的金额)

在不添加额外价格的情况下,我是否缺少任何付款钩子。

提前致谢。

【问题讨论】:

  • 哪个支付网关?

标签: php wordpress woocommerce


【解决方案1】:

你必须使用下面的钩子woocommerce_cart_calculate_fees。

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.woocommerce.com/document/add-a-surcharge-to-cart-and-checkout-uses-fees-api/

add_fee 参考:http://woocommerce.wp-a2z.org/oik_api/wc_cartadd_fee/

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2014-03-16
    • 1970-01-01
    • 2014-10-30
    • 2015-03-30
    • 2021-04-29
    • 2017-02-07
    • 2018-02-03
    • 1970-01-01
    相关资源
    最近更新 更多