Using Gravity Forms As A WooCommerce Order form

Using Gravity Forms As A WooCommerce Order form

Using Gravity Forms As A WooCommerce Order form – I was working with one of my clients this week to create an order form for a WooCommerce site.

Sometimes you don’t want your customers to jump through the hoops of visiting a single product page, adding to cart, visiting the cart and then hitting the checkout.

If your customer makes repeat purchases of the same products all the time, why not just have a very simple order form listing all the products, they can then select one or more products, set the quantity and with a single click add everything to the cart and then go directly to checkout.

I tried a number of native WooCommerce solutions then I went back to my old friend gravity forms and I was able to create a frictionless form to add multiple products to cart from a single page.

Create a form with the products

I created a form with a series of numeric fields on it, the field title was the product name and I used the description label for the prices.

The default value of the number field is 0, then the customer can increase the quantity in that field.

Then they click the checkout button.

Create on submission code to add to cart

Upon submission of the form I have some code that grabs the values of the numeric fields and translates that to a programmatic add to cart for those products.

See the code below, it checks to see if the field is not zero then it runs an add to cart with the appropriate product ID and quantity.

add_action( 'gform_after_submission_19', 'nm_add_eur_products_cart', 10, 2 );

function nm_add_eur_products_cart( $entry, $form ) {

	
	if(rgar( $entry, '5' ) >0){
		
		  WC()->cart->add_to_cart( '6292',rgar( $entry, '5' )  );
	}
	
	if(rgar( $entry, '6' ) >0){
	
		  WC()->cart->add_to_cart( '6294',rgar( $entry, '6' )  );	
	}
	
	if(rgar( $entry, '7' ) >0){
		WC()->cart->add_to_cart( '6296',rgar( $entry, '7' )  );	
			
	}  
}

Add A Redirect to the checkout

The last step of the process is to add a redirect upon submission to the checkout page.

This is accomplished with a standard Gravity Form redirect confirmation.

Video

Here’s a walkthrough of this form in action

Wrap Up – Using Gravity Forms As A WooCommerce Order form

I’m a huuuge fan of gravity forms, I use it whenever I need to capture front end data from a customer, it’s built in hooks and actions make it flexible enough to do almost any job.

If you need help with a custom Gravity form solution, give me a shout, it’s my favourite type of project.

Photo by micheile henderson on Unsplash

Get A No Obligation Quote

Do You Need Help With Your WooCommerce Site?

Click through to the next page and complete the form to get a free no obligation quote to fix any issue you are having with your WooCommerce site.