0

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.

Ahmad Tahhan
  • 125
  • 14
  • @LoicTheAztec I see, do you have any clue where I should start from? – Ahmad Tahhan Aug 15 '20 at 19:35
  • 2
    Something bit like https://stackoverflow.com/a/55521313/3730754 but without the field… See [**this answers**](https://stackoverflow.com/search?q=user%3A3730754+jquery+ajax+woocommerce_cart_calculate_fees) using `woocommerce_cart_calculate_fees` hook, Ajax and jQuery… Now you can make your own code attempt and if you have problems ask a new question providing your code and explanations. – LoicTheAztec Aug 15 '20 at 19:38

0 Answers0