我知道我可以使用以下代码向购物车添加费用,但它只是向购物车添加了一般费用。Woocommerce 承认特定的运费,我想知道是否有办法通过以下方法增加费用,woocommerce 将其视为“运费”特定费用。某种元数据被添加到运输特定费用中。我们的 API 没有将这些费用视为运费,因此不会记录它们,这就是我想要解决的问题。
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, '' );
}