Created
January 16, 2016 01:04
-
-
Save reinnovating/3518d1e22fa8f6803391 to your computer and use it in GitHub Desktop.
Add overlay images for new and sold out products on the product list pages in WooCommerce.
This file contains 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 | |
class shopTheme { | |
public function __construct () { | |
/* Add overlay images for products in shop list */ | |
add_action('woocommerce_before_shop_loop_item_title', array($this , 'add_overlay_images'), 10); | |
} | |
/* Add overlay images for products in shop list*/ | |
public function add_overlay_images(){ | |
global $product; | |
//If product is in stock | |
if ( $product-> is_in_stock() ) { | |
//If the product was created less than 30 days ago, echo image for new product | |
if ( strtotime( $post->post_date ) > strtotime( '-30 days' )){ | |
echo '<img src="new.png" alt="New product" class="new" />'; | |
} | |
} else { | |
echo '<img src="sold-out.png" alt="Sold out" class="sold-out" />'; | |
} | |
} | |
} | |
new shopTheme(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment