Site icon Anthony Carbon

Woocommerce add to cart redirection using WooCommerce – Gravity Forms Product Add-Ons plugins.

After clicking add to cart button in product category, this will be redirecting to single product and the same time your current product is added to cart page. How to do that? Follow the steps bellow.

Step 1:

Make sure to change the product URL. Just add “?add_to_cart=true” after the product URL. Example.

http://www.wptaskforce.com/product/baby-boy-bouquet/?add_to_cart=true

Step 2:

Copy and paste the codes below to your JS file.

jQuery( document ).ready(function( $ ) {
	var getUrlParameter = function getUrlParameter(sParam) {
		var sPageURL = decodeURIComponent(window.location.search.substring(1)),
			sURLVariables = sPageURL.split('&'),
			sParameterName,
			i;
	
		for (i = 0; i < sURLVariables.length; i++) {
			sParameterName = sURLVariables[i].split('=');
	
			if (sParameterName[0] === sParam) {
				return sParameterName[1] === undefined ? true : sParameterName[1];
			}
		}
	};
	var ac_add_to_cart = getUrlParameter( 'add_to_cart' );
	if( ac_add_to_cart == 'true' && $( '.mk-product-details .single_add_to_cart_button' ).length ){
  		var ac_url = $( '.gform_wrapper input[name="_wp_http_referer"]' ).val();
     	var ac_split = ac_url.split( '?add_to_cart=true' ); 
		$( '.gform_wrapper input[name="_wp_http_referer"]' ).val( ac_split[0] );
		$( '.mk-product-details .single_add_to_cart_button' ).trigger( 'click' );
	}
});

Step 3:

You can now check the function if it is working.

Exit mobile version