Skip to content

Instantly share code, notes, and snippets.

@jcasabona
Created August 14, 2018 13:48
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jcasabona/fa41e9c0f0b0534fdda6822cc4e185a7 to your computer and use it in GitHub Desktop.
Save jcasabona/fa41e9c0f0b0534fdda6822cc4e185a7 to your computer and use it in GitHub Desktop.
Discount Referrer Pseudo Code
<?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