如何获取单选按钮组,以更新WooCommerce结帐页上选中的结算总计中列出的Surchage,然后选择其中一个。单选按钮A的选择需要增加0.05%作为附加,因为单选按钮B将增加0.10%。WooCommerce基于结账中的单选按钮的动态Surchage
我知道我可以添加静态收费有以下:
add_action('woocommerce_cart_calculate_fees','woocommerce_custom_surcharge');
function woocommerce_custom_surcharge() {
global $woocommerce;
if (is_admin() && ! defined('DOING_AJAX'))
return;
// $percentage is what will change based on which button is selected A or B
// however this is not executed after the page is loaded
$percentage = 0.05;
$surcharge = ($woocommerce->cart->cart_contents_total + $woocommerce->cart->shipping_total) * $percentage;
$woocommerce->cart->add_fee('Service Fee', $surcharge, true, 'standard');
}