php - WooCommerce Dynamic Surchage based on radio button in checkout -
how radio button group update surchage listed in checkout total on woocommerce checkout page when 1 selected, other. selection of radio button needs add 0.05 percent surcharge as, radio button b add 0.10 percent.
i know can add static surcharge following:
add_action( 'woocommerce_cart_calculate_fees','woocommerce_custom_surcharge' ); function woocommerce_custom_surcharge() { global $woocommerce; if ( is_admin() && ! defined( 'doing_ajax' ) ) return; // $percentage change based on button selected or b // not executed after page loaded $percentage = 0.05; $surcharge = ( $woocommerce->cart->cart_contents_total + $woocommerce->cart->shipping_total ) * $percentage; $woocommerce->cart->add_fee( 'service fee', $surcharge, true, 'standard' ); }
maybe started. don't think automatically add fee, haven't tested , idea:
jquery(document).ready(function($){ if ( typeof wc_checkout_form === 'undefined' || ) { return false; } $checkout_form = $( 'form.checkout' ); $checkout_form.on( 'change', '.your_radio_buttons_class', function(){ wc_checkout_form.wc_checkout_form(); }); });
i believe need utilize checkout script, want ensure custom script loaded after checkout.js
.
Comments
Post a Comment