Accept coupon code automatically with URL

Hi,

I would like to create an URL with coupon code. So when someone open this URL, the discount already activated. Is it possible?

Thank you!

  • Dimitris
    • Support Star

    Hey there Adam,

    hope you're doing good and thanks for reaching us! :slight_smile:

    In order to do so you should create a little MU plugin by creating the following file in your installation
    /wp-content/mu-plugins/embed-coupon.php
    (simply create the /mu-plugins/ folder if doesn't exist already)

    In that file insert the following snippet

    <?php
    function my_coupon() {
     	if ( $_GET['coupon'] ) {?>
    	<script type="text/javascript">
         jQuery(function(){
           jQuery('.coupon-box input').val('<?php echo $_GET['coupon']; ?>');
           jQuery('.apply-coupon-link').trigger('click');
         })
      </script>
    <?php }
    }
    add_action( 'wp_footer', 'my_coupon' );

    Now if you navigate to http://your-domain.com/pro-site/?coupon=CODE the CODE part of the URL (which is the actual coupon code) should be in place of the coupon input and the sales prices should be visible in different levels.

    Hope that was some help, feel free to post back here if more assistance is required!

    Warm regards,
    Dimitris

  • Dimitris
    • Support Star

    Hey Adam,

    I'm glad that worked for you! :slight_smile:

    As this is a generic PHP/JS workaround which can be applied for every form in your website, I'd rather keep that in a little MU plugin, like you do, in order to preserve that.
    By doing so you're also protected from plugins and core updates so you shouldn't worry any longer about it.

    Despite my thoughts though, If you still think that this could be a good addition, feel free to create a new thread about it (and any other suggestions that you might have) in our Features & Feedback section. :slight_smile:

    Warm regards,
    Dimitris

Thank NAME, for their help.

Let NAME know exactly why they deserved these points.

Gift a custom amount of points.