pronamic/pronamic-payment-gateways-fees-for-woocommerce
最新稳定版本:v1.0.3
Composer 安装命令:
composer require pronamic/pronamic-payment-gateways-fees-for-woocommerce
包简介
This WordPress plugin adds settings to all WooCommerce gateways to add a fixed and/or variable (percentage) fee.
关键字:
README 文档
README
Pronamic Payment Gateways Fees for WooCommerce
This WordPress plugin adds settings to all WooCommerce gateways to add a fixed and/or variable (percentage) fee.
Introduction
This WordPress plugin adds settings to all WooCommerce gateways to add a fixed and/or variable (percentage) fee.
Installation
composer require pronamic/pronamic-payment-gateways-fees-for-woocommerce
\Pronamic\WooCommercePaymentGatewaysFees\Plugin::instance()->setup();
Screenshots
Flow
WooCommerce recommends using the woocommerce_cart_calculate_fees hook to add fees:
We suggest using the action woocommerce_cart_calculate_fees hook for adding fees.
This hook is called as soon as the WC()->cart->calculate_totals() function is called, WooCommerce uses the WC_Cart_Totals class to calculate totals:
class-wc-cart.php
/** * Calculate totals for the items in the cart. * * @uses WC_Cart_Totals */ public function calculate_totals() { $this->reset_totals(); if ( $this->is_empty() ) { $this->session->set_session(); return; } do_action( 'woocommerce_before_calculate_totals', $this ); new WC_Cart_Totals( $this ); do_action( 'woocommerce_after_calculate_totals', $this ); }
When creating a WC_Cart_Totals instance, the WC_Cart_Totals->calculate() function is executed:
class-wc-cart-totals.php
/** * Run all calculation methods on the given items in sequence. * * @since 3.2.0 */ protected function calculate() { $this->calculate_item_totals(); $this->calculate_shipping_totals(); $this->calculate_fee_totals(); $this->calculate_totals(); }
What can be seen here is that the final totals are calculated after calculating the fee totals. This means that the order total is not yet available within the woocommerce_cart_calculate_fees hook. In other words, within the woocommerce_cart_calculate_fees hook the result of $cart->get_total( '' ) will always be 0.
This is inconvenient because the payment gateway fees are often based on the total amount to be paid. That's why we hook into the woocommerce_after_calculate_totals hook and recalculate the totals again. This extra calculation seems double, but it seems to be the easiest way to reliably request the cart total.
Links
统计信息
- 总下载量: 174
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 3
- 点击次数: 0
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: proprietary
- 更新时间: 2023-10-31


