如何獲取單選按鈕組,以更新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');
}