Created
October 19, 2021 20:34
Star
You must be signed in to star a gist
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 | |
/* | |
Plugin Name: WooCommerce Sale Price First | |
Plugin URI: https://www.damiencarbery.com/ | |
Description: Move the Sale Price to be before the Normal Price in the html but display as Normal-then-Sale. This is because Google Merchant is not reading the sale price. | |
Author: Damien Carbery | |
Version: 0.1 | |
*/ | |
add_filter( 'woocommerce_format_sale_price', 'dcwd_sale_price_first', 10, 3 ); | |
function dcwd_sale_price_first( $price, $regular_price, $sale_price ) { | |
$price = '<ins>' . ( is_numeric( $sale_price ) ? wc_price( $sale_price ) : $sale_price ) . '</ins> <del aria-hidden="true">' . ( is_numeric( $regular_price ) ? wc_price( $regular_price ) : $regular_price ) . '</del>'; | |
// This CSS should be moved to your stylesheet or Additional CSS in Customizer. | |
$style = '<style>.single-product div.product p.price { display: flex; } .single-product div.product p.price ins { order: 2; padding-left: 0.5em; }</style>'; | |
return $price . $style; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment