Skip to content

Instantly share code, notes, and snippets.

@weartstudio
Created December 17, 2020 12:32
Show Gist options
  • Save weartstudio/41b801a1a52c6558eb625b359ad74837 to your computer and use it in GitHub Desktop.
Save weartstudio/41b801a1a52c6558eb625b359ad74837 to your computer and use it in GitHub Desktop.
Variable products tax display - enabled suffix
add_filter('woocommerce_get_price_suffix', function ( $html, $product, $price, $qty ) {
if ( ! $html && $product instanceof WC_Product_Variable) {
// Copied from plugins/woocommerce/includes/abstracts/abstract-wc-product.php#get_price_suffix
if ( ( $suffix = get_option( 'woocommerce_price_display_suffix' ) )
&& wc_tax_enabled()
&& 'taxable' === $product->get_tax_status()
) {
$replacements = array(
'{price_including_tax}' => wc_price( wc_get_price_including_tax( $product, array( 'qty' => $qty, 'price' => $price ) ) ),
'{price_excluding_tax}' => wc_price( wc_get_price_excluding_tax( $product, array( 'qty' => $qty, 'price' => $price ) ) ),
);
$html = str_replace( array_keys( $replacements ), array_values( $replacements ), ' <small class="woocommerce-price-suffix">' . wp_kses_post( $suffix ) . '</small>' );
}
}
return $html;
}, 10, 4);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment