Skip to content

Instantly share code, notes, and snippets.

@faurelia
Created November 25, 2021 10:36
Show Gist options
  • Select an option

  • Save faurelia/eaf882f204c85008949c836a84eefb64 to your computer and use it in GitHub Desktop.

Select an option

Save faurelia/eaf882f204c85008949c836a84eefb64 to your computer and use it in GitHub Desktop.
WooCommerce: Check if a product is valid for coupon
<?php
function action_woocommerce_before_shop_loop_item_title() {
$product = wc_get_product();
$coupon = new WC_Coupon('BF50');
if ( $coupon->is_valid_for_product( $product ) ) {
echo '<div class="onsale">Sale!</div>';
}
}
add_action( 'woocommerce_before_shop_loop_item_title', 'action_woocommerce_before_shop_loop_item_title', 10, 0 );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment