Say you have added a product called Business Growth Calculator in WooCommerce.
Now you want to promote that product in a Post / Article on Measuring Business Growth.
Instead of directing the user to the product page, you want the visitor to be able to add the product to the cart from the post / article as it creates an unnecessary step.
How do you do that? Using WooCommerce Add-to-Cart Shortcode.
Step 1 – Get Product Details
Navigate to WP Admin > Products > [choose the product for which you want to create a custom add-to-cart button] > Edit Product.
Look at the URL and it will look something like this:
Write down the post id (218 in the example above).
Also, write down the SKU number found in Product Data metabox. The SKU ID is optional but write it down anyway.
Step 2 – Insert the Add-to-Cart Shortcode
Navigate to the post / page / article in which you want to add the cart button and click in the text editor wherever you want to display the add-to-cart button.
Find the WOO button in the text editor toolbox and click on it. From the dropdown click on Product price /cart button.
This will insert the following Shortcode.
What you need to insert into that are the IDs you wrote down in Step 1.
add_to_cart id=”218″ sku=”Prod-03″
Sku is optional, however, id is required.
Click save and view post / page and you will find that there is a nice little add-to-cart button for that product. Now the user does not first navigate to the product page before being able to add that product to their cart.