I am using WooCommerce All Products Subscription to let users convert their cart total into a subscription or to purchase one time only.
The subscription plugin I am using gives the user the choice to purchase as one time or a monthly subscription on the Cart page (e.g One-time purchase or Renew every month).
What I am trying to do is to add an extra fee to the cart total if the user chooses One-time purchase, for example, if the cart total is $100 and the user chooses a One-time purchase the cart total would change as an extra fee will be added. if the user choose to subscribe, then the fee should be removed.
I already tried to use jQuery alongside PHP but without any luck.
Here is the current PHP function that adds an extra fee, but currently it's adding a fee anyway.
add_action( 'woocommerce_cart_calculate_fees', 'extra_fee', 10, 1 );
function extra_fee( $cart ) {
if ( is_admin() && ! defined( 'DOING_AJAX' ) ) return;
$cart_total = $cart->cart_contents_total;
$feeAmount = 50;
$cart->add_fee( __( "Extra Fee", "woocommerce" ), $feeAmount, false );
}
the function is placed in functions.php
in a child theme.