• Resolved ozcoolie

    (@ozcoolie)


    Hi, I’m a developer but very new to WP and WC so still finding my way round. I copied the following function from Woo docs as a starter…

    
    add_action( 'woocommerce_cart_calculate_fees','woocommerce_custom_surcharge' );
    function woocommerce_custom_surcharge() {
      global $woocommerce;
    	if ( is_admin() && ! defined( 'DOING_AJAX' ) )
    		return;
    
     	$county 	= array('US');
    	$percentage 	= 0.01;
    
    	if ( in_array( $woocommerce->customer->get_shipping_country(), $county ) ) :
    		$surcharge = ( $woocommerce->cart->cart_contents_total + $woocommerce->cart->shipping_total ) * $percentage;
    		$woocommerce->cart->add_fee( 'Surcharge', $surcharge, true, 'standard' );
    	endif;
     
    }
    

    However, AJAX-checkout just removes it again. Also tried adding the fee directly to WC()->cart->add_fee( ‘Fee’, ’10’ ) with the same result.

    I have cleared cache and tried to checkout as guest to see if the issue is related to recurring fees or not. Also tried adding the following, although we’re not offering subscriptions…

    
    add_filter( 'woocommerce_subscriptions_is_recurring_fee', '__return_true' );
    

    No matter what I have tried, AJAX removes it again. I have disabled all plugins other than WC and I’m using the Shopfront theme. What am I missing?

    • This topic was modified 5 years, 5 months ago by ozcoolie.

    The page I need help with: [log in to see the link]

Viewing 1 replies (of 1 total)
Viewing 1 replies (of 1 total)
  • The topic ‘How to stop AJAX from removing fees’ is closed to new replies.