/**********************************************************************/ // add extra fee option at checkout // See: https://stackoverflow.com/questions/32119053/woocommerce-custom-checkout-field-to-add-fee-to-order-ajax add_action( 'woocommerce_after_checkout_billing_form', 'add_fee_option_to_checkout' ); function add_fee_option_to_checkout( $checkout ) { echo '

Pay Bank Fee?

Thanks for your donation! Our bank charges a 3% credit card processing fee. Tick the box if you are willing to pay the fee on top of your donation. '; woocommerce_form_field( 'add_fee_option', array( 'type' => 'checkbox', 'class' => array('add_fee_option form-row-wide'), 'label' => __('Pay bank transaction fees? '), 'placeholder' => __(''), ), $checkout->get_value( 'add_fee_option' )); echo '

'; } add_action( 'wp_footer', 'woocommerce_add_fee_option' ); function woocommerce_add_fee_option() { if (is_checkout()) { ?> cart->cart_contents_total + $woocommerce->cart->shipping_total ) * $percentage + 0.49; $woocommerce->cart->add_fee( 'Bank Fee', $surcharge, true, '' ); } }

October 2016