WooCommerce Dynamic Surcharge Raido Button
-
How do I get a Radio Button Group to update a surchage listed in the checkout total on a WooCommerce Checkout page when one is selected, then the other. The selection of Radio Button A needs to add 0.05 percent as a surcharge where as, Radio Button B would add 0.10 percent.
I know that I can add a static surcharge with the following:
`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’ );}`
The topic ‘WooCommerce Dynamic Surcharge Raido Button’ is closed to new replies.