Created
August 14, 2018 13:48
-
-
Save jcasabona/fa41e9c0f0b0534fdda6822cc4e185a7 to your computer and use it in GitHub Desktop.
Discount Referrer Pseudo Code
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
add_action('woocommerce_before_cart_table', 'discount_frol_url'); | |
function discount_from_url() { | |
global $woocommerce; | |
if( 'https://wpsessions.com' == wp_get_referer() ) { | |
$coupon_code = 'WPSESSIONS'; | |
if (!$woocommerce->cart->add_discount( sanitize_text_field( $coupon_code ))) { | |
$woocommerce->show_messages(); | |
} | |
echo '<div class="woocommerce_message"><strong>Hello WPSessions Person! a Discount code has been automatically applied!</strong></div>'; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment