Additional, optional fee on Woocommerce Checkout [closed]
IT Nursery
May 13, 2022
0
I’m building a shop based on WooCommerce. I need to add an extra checkbox on the checkout page called Shipping Insurance. Once the field is checked, i need to add an extra $3 to the Order Total. I was able to add a fixed fee this way:
function woo_add_cart_fee() {
global $woocommerce;
$woocommerce->cart->add_fee( __('Shipping Insurance', 'woocommerce'), 3 );
}
add_action( 'woocommerce_before_calculate_totals', 'woo_add_cart_fee' );
The problem is that this will add a fixed $3 to the order total, so its not optional. Any idea how to proceed with this issue?
2 Answers 2
Ok, so this is how i did it.
Create a product called Shipping Insurance which is $3, make sure its a hidden product(Catalog Visibility on the right side)
Use the following code in your theme’s functions.php file: