Last active
June 19, 2020 09:48
-
-
Save vyskoczilova/2ff56afcfd4c75338fb7f0be3a5615c2 to your computer and use it in GitHub Desktop.
Tax placeholders for Price Display Suffix
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 | |
/** | |
* @snippet Tax placeholders for Price Display Suffix | WooCommerce | |
* @comment Use "{tax_rate}" and "{tax_rate_label}" placeholder for displaying the product tax rate and its label | |
* @source https://gist.github.com/vyskoczilova/2ff56afcfd4c75338fb7f0be3a5615c2 | |
* @author Karolína Vyskočilová (https://kybernaut.cz) | |
* @testedwith WooCommerce 4.2 | |
*/ | |
// ------------------- | |
add_filter( 'woocommerce_get_price_suffix', 'replacement_for_tax_class_name', 99, 4 ); | |
function replacement_for_tax_class_name( $html, $product, $price, $qty ){ | |
$tax_rates = WC_Tax::get_rates( $product->get_tax_class() ); | |
$tax_rate_value = ''; | |
$tax_rate_label = ''; | |
if(!empty($tax_rates)){ | |
foreach($tax_rates as $tax ){ | |
$tax_rate_value = rtrim($tax['rate'], "0"); | |
$tax_rate_value = rtrim($tax_rate_value, "."); | |
$tax_rate_label = $tax['label']; | |
} | |
} | |
$replacements = array( | |
'{tax_rate}' => $tax_rate_value, | |
'{tax_rate_label}' => $tax_rate_label, | |
); | |
$html = str_replace( array_keys( $replacements ), array_values( $replacements ), $html ); | |
return $html; | |
} |
@Ansolon glad it helped :) (I assume that you have the newest WooCommerce so I bumped the version)
Yes its working on wordpress 5.4.2 and woocommerce 4.2.0
Thanks again
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
very thanks i exactly looking for it days