Created
November 25, 2021 10:36
-
-
Save faurelia/eaf882f204c85008949c836a84eefb64 to your computer and use it in GitHub Desktop.
WooCommerce: Check if a product is valid for coupon
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 | |
| 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