Skip to content

Instantly share code, notes, and snippets.

@sholex
Last active November 12, 2025 13:30
Show Gist options
  • Select an option

  • Save sholex/4064fc2b656c0857a78228cf5324b370 to your computer and use it in GitHub Desktop.

Select an option

Save sholex/4064fc2b656c0857a78228cf5324b370 to your computer and use it in GitHub Desktop.

Revisions

  1. sholex renamed this gist Jul 2, 2019. 1 changed file with 0 additions and 0 deletions.
    File renamed without changes.
  2. sholex created this gist Jun 15, 2019.
    44 changes: 44 additions & 0 deletions gistfile1.txt
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,44 @@
    <?php
    /**
    * Single Product Sale Flash
    *
    * This template can be overridden by copying it to yourtheme/woocommerce/single-product/sale-flash.php.
    *
    * HOWEVER, on occasion WooCommerce will need to update template files and you
    * (the theme developer) will need to copy the new files to your theme to
    * maintain compatibility. We try to do this as little as possible, but it does
    * happen. When this occurs the version of the template file will be bumped and
    * the readme will list any important changes.
    *
    * @see https://docs.woocommerce.com/document/template-structure/
    * @author WooThemes
    * @package WooCommerce/Templates
    * @version 1.6.4
    */
    if ( ! defined( 'ABSPATH' ) ) {
    exit; // Exit if accessed directly
    }
    global $post, $product;
    ?>

    <?php if ( $product->is_on_sale() ) : ?>

    <?php
    if ($product->is_type( 'simple' )) {
    $sale_price = $product->get_sale_price();
    $regular_price = $product->get_regular_price();
    }
    elseif($product->is_type('variable')){
    $sale_price = $product->get_variation_sale_price( 'min', true );
    $regular_price = $product->get_variation_regular_price( 'max', true );
    }


    $discount = round (($sale_price / $regular_price -1 ) * 100);

    ?>

    <?php echo apply_filters( 'woocommerce_sale_flash', '<span class="onsale-icon"> ' . $discount . ' %</span>', $post, $product ); ?>

    <?php endif;
    /* Omit closing PHP tag at the end of PHP files to avoid "headers already sent" issues. */