Created
May 30, 2024 02:52
-
-
Save shameemreza/aebd761064a063d054cb4c48fcde8949 to your computer and use it in GitHub Desktop.
Restore price suffix for variable product in WooCommerce
This file contains hidden or 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
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