• dipeshcct

    (@dipeshcct)


    Hello,

    I want to add fee on cart page using AJAX. Below I write function for it.

    function woo_add_cart_fee() {
    	if ( ! $_POST || ( is_admin() && ! is_ajax() ) ) {
            return;
        }
    	global $woocommerce;
        $extracost = 10;
    	$woocommerce->cart->add_fee( 'Surcharge', $extracost, true, '' );
    	if(is_ajax()){
            add_action('woocommerce_after_cart', 'cart_select_change_js', 10);
    		echo wc_get_template( 'cart/cart-totals.php' );
    		exit;
    	}
    }

    It add extra fee in cart object but can’t update total value.

Viewing 1 replies (of 1 total)
  • carver1g

    (@carver1g)

    Not sure if this will be of any help but this is what I use to add a handling fee to the cart and checkout:

    //Add handling fee to cart and checkout
    add_action( ‘woocommerce_cart_calculate_fees’,’endo_handling_fee’ );
    function endo_handling_fee() {
    global $woocommerce;

    if ( is_admin() && ! defined( ‘DOING_AJAX’ ) )
    return;

    $fee = 6.99;
    $woocommerce->cart->add_fee( ‘Handling’, $fee, true, ‘standard’ );
    }

Viewing 1 replies (of 1 total)
  • The topic ‘Add fee on cart page using AJAX’ is closed to new replies.