这是一个简单的片段,可以在每次付款时向购物车添加费用。
添加费用到结帐 – WooCommerce
/**
* @snippet WooCommerce Add fee to checkout
* @sourcecode https://businessbloomer.com/?p=17446
* @author Rodolfo Melogli
* @testedwith WooCommerce 2.6.4
*/
function bbloomer_add_checkout_fee() {
global $woocommerce;
// Edit "Fee" and "5" below to control Label and Fee Amount
$woocommerce->cart->add_fee( __('Fee', 'woocommerce'), 5 );
}
add_action( 'woocommerce_cart_calculate_fees', 'bbloomer_add_checkout_fee' );
为特定支付网关 – WooCommerce 添加费用
/**
* @snippet WooCommerce Add fee to checkout for a gateway ID
* @sourcecode https://businessbloomer.com/?p=17446
* @author Rodolfo Melogli
* @testedwith WooCommerce 2.6.4
*/
function bbloomer_add_checkout_fee_for_gateway() {
global $woocommerce;
$chosen_gateway = $woocommerce->session->chosen_payment_method;
if ( $chosen_gateway == 'cheque' ) {
// Note: edit "Fee" and "5" below to control Label and Fee Amount
$woocommerce->cart->add_fee( __('Fee', 'woocommerce'), 5 );
}
}
add_action( 'woocommerce_cart_calculate_fees', 'bbloomer_add_checkout_fee_for_gateway' );
可以在哪里添加此代码?
您可以将 PHP 代码片段放置在主题或子主题的 functions.php 文件的底部(如果是 CSS 代码,请添加到主题的 style.css 文件底部),修改之前建议先备份原始文件,若出现错误请先删除此代码。
这段代码是否正常可用?
或者是您有更好的解决方案想要分享?请到薇晓朵 WooCommerce 中文论坛留言告知,我们希望可以帮到更多国内的 WooCommerce 用户也希望您的参与。
需要关于 WooCommerce 的帮助?
请观看我们提供的免费视频教程或到薇晓朵 WooCommerce 中文论坛提问,会有专业技术团队提供相关帮助。