Skip to content

Instantly share code, notes, and snippets.

@WhiteHatJoker
Created October 18, 2021 22:59
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 WhiteHatJoker/f67585f9e8401397df0a2b2757fa75ea to your computer and use it in GitHub Desktop.
Save WhiteHatJoker/f67585f9e8401397df0a2b2757fa75ea to your computer and use it in GitHub Desktop.
Add out of stock flash text above featured image on single product page

Add out of stock flash text above featured image on single product page

If you have out of stock flash displayed on product catalog pages, but not on single product pages, you can follow my instructions to fix this.

Installation

  1. Copy over the code from functions.php to your WordPress copy of that file.
  2. Use Chrome dev tools to identify the class of div which is used to output 'Out of stock' flash on products category page of your website.
  3. Update line 6 printf( '<div class="fusion-out-of-stock"><div class="fusion-position-text">%s</div></div>', __( 'Out of Stock', 'Avada' ) ); with your div class details. Keep in mind: The div class used in this file does belong to Avada and may not work on other themes.
//Function to add out of stock flash to images on single product page
function avada_show_single_product_outofstock_flash( $img_html ) {
global $product;
if ( ! $product->is_in_stock() ) {
printf( '<div class="fusion-out-of-stock"><div class="fusion-position-text">%s</div></div>', __( 'Out of Stock', 'Avada' ) );
}
return $img_html;
}
add_filter( 'woocommerce_single_product_image_html', array( $this, 'avada_show_single_product_outofstock_flash' ));
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment