Skip to content
Advertisement

GET a coupon code via URL and apply it in WooCommerce Checkout page [closed]

I have a WooCommerce website and when customer add-to-cart a product, it is get redirected to checkout page, so cart page is not accessible.

I would like to apply coupon via URL (GET) on checkout page, with something like https://example.com/?coupon_code=highfive.

When customer click this URL then the coupon code is stored in browser sessions. Then if he add-to-cart any product then the coupon is applied into checkout page.

Is this possible?

Advertisement

Answer

Update 3: This can be done in a very simple way with the following 2 hooked functions:

  • The first one will catch the coupon code in the Url and will set it in WC_Sessions.
  • The second one will apply the coupon code from session in checkout page.

Here is this code:

JavaScript

Code goes in function.php file of the active child theme (or active theme). Tested and works

Inspired from this answer code, Lukasz Wiktor has published a plugin: Woo Coupon URL

User contributions licensed under: CC BY-SA
10 People found this is helpful
Advertisement