Prevent Refresh from Adding Another Product in WooCommerce

Update: this issue has been resolved. WooCommerce now replaces the `add-to-cart` query arg with `added-to-cart` on success.

Prevent items from being mistakenly added to the cart multiple times.

Mountain America Jerky uses the WooCommerce eCommerce plugin for WordPress, and they were having an issue: when users added a product to their cart then refreshed, the item was being added again. Also, when customers added items to their cart, then hit back, they got the dreaded “Confirm Form Resubmission” notice.

To solve this issue, I added a redirection when users added products to their cart. The code hooks into WooCommerce’s `woocommerce_add_to_cart_action` function, located in `/woocommerce/woocommerce-functions.php`.

Here’s the code that you should add to your theme’s `functions.php` file, or to your own custom plugin:

add_action('add_to_cart_redirect', 'resolve_dupes_add_to_cart_redirect');
 
function resolve_dupes_add_to_cart_redirect($url = false) {
 
     // If another plugin beats us to the punch, let them have their way with the URL
     if(!empty($url)) { return $url; }
 
     // Redirect back to the original page, without the 'add-to-cart' parameter.
     // We add the `get_bloginfo` part so it saves a redirect on https:// sites.
     return get_bloginfo('wpurl').add_query_arg(array(), remove_query_arg('add-to-cart'));
 
}

I hope this helps someone else with the same issue!

Mountain America Jerky Redesign Launched

Mountain America Jerky Redesign

Mountain America Jerky Before Redesign Mountain America Jerky - After Redesign
Mountain America Jerky - Before and After Redesign

I’m happy to announce that today the new Mountain America Jerky website launched. Check out the site and try some of their crazy-good Garlic Black Pepper Beef Jerky. One perk of working with a nice client who sells beef jerky is getting samples of the product! Seriously, though, it’s the best jerky I’ve ever had.

I started working with Mountain America Jerky as a SEO. Jerky is a competitive field, and they wanted to improve their ranking. After working with Chuck on the website’s optimization, he told me he wanted to go big and rebrand the site. The result is a rustic, functional, beautiful website. Continue reading “Mountain America Jerky Redesign Launched”