Price display suffix not showing with same price variations
-
Price display suffix not showing with same price variations
This topic has been left unresolved, the issue still remains. The price suffix should appear in these circumstances without having to add custom code or another plugin.
-
Hello @nunowp while any custom coding of WooCommerce is not supported in this forum I’d like to get a better understanding of what it is you’re attempting to do here. Can you please submit the hook used to get a suffix to show in the first place? Thanks.
Hi, thanks for your reply.
As I mentioned, I don’t use any custom code, just the {price_including_tax} suffix in the woocommerce tax settings.The thing is, any suffix doesn’t appear if the product has variations all with the same price. I think this is a bug that needs to be fixed.
Hello @nunowp thanks for clarifying.
I’m referring to your older post you linked above here which then linked to code snippets and other sites. It wasn’t clear or stated that any custom code was added, however, I’m just making absolutely sure that we’re all on the same page here.
I’m not aware of what you’re attempting to do. I’ll let one of our support members answer this.
I could help maybe if you had screenshots or a loom of what you’re attempting to do in the backend.
Hello nunowp
Thank you for contacting Woo support.
This topic has been left unresolved, the issue still remains. The price suffix should appear in these circumstances without having to add custom code or another plugin.
Could you please explain the issue you are facing?
Also, share screenshots of WooCommerce settings with me to understand the problem in a better way.Your case may be different than the post you shared.
I will be happy to look into it and work on a solution with you.Looking forward to your response. ??
Best regards.
Hello,
Thank you for your reply.
Here are the screenshots of the settings.
The 2nd image is of a variable product (no suffix on the price).
The 3rd image is of a simple product (suffix appears correctly).https://ibb.co/HXxXRrT
https://ibb.co/GM9Kzwj
https://ibb.co/DtWzzNSI don’t think I’ve explained myself well, what I mean is that the price suffix under the product description doesn’t appear when the product has variations and it should. Thanks.
Hi @nunowp
This is expected behavior as documented inline here: https://github.com/woocommerce/woocommerce/blob/5d7f6acbcb387f1d51d51305bf949d07fa3c4b08/includes/class-wc-product-variable.php#L132-L147
This features is disabled at VARIABLE product level because it’s not possible to “know” the prices including/excluding tax. Prices come from variations. Variations can have different tax classes. So it’s not possible to know what rate to apply to which price.
However, you can customize it using the
woocommerce_get_price_html
filter hooks if needed for variable products. To do so, add this custom code snippet to your child theme’s functions.php, and everything will start to work as normal products: https://gist.github.com/shameemreza/aebd761064a063d054cb4c48fcde8949add_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);
I hope this helps! Please let us know how it goes or if you need further assistance.
Hi @shameemreza
Thank you for your help.
The code works. However, as my suffix is ({price_including_tax} w/VAT) it works fine when the variations all have the same price, but it doesn’t make sense when the variations have different prices as it always shows the price of the variation with the lowest price under the product title.
I managed to solve it by changing this field “. wp_kses_post( $suffix )” for “. wp_kses_post( ‘ w/VAT’ )” on line 12.
However, when the variations are all the same price, it naturally also shows this suffix and I end up without the price with VAT calculated because when I choose the variation, if they are the same, by default no price appears below the variation box because it’s supposed to be in the title.
By the way, another question: do you expect a significant drop in page performance with this type of custom code in functions.php? Thank you
Hello @nunowp,
We are glad to hear you’ve found a workaround by modifying the code. However, I also understand that this solution does not work fully when all variations have the same price.
In this case, you need to make changes in your code to check if all variations are the same price before applying your custom suffix. This I’m afraid is out of our support scope, and you may have to reach out to a developer for further assistance.
do you expect a significant drop in page performance with this type of custom code in functions.php??
Adding custom code to your functions.php file should not significantly affect your page performance, as long as the code is well-written and efficient. It’s always a good practice to monitor your site’s performance to ensure that any customizations are not negatively impacting your site speed or functionality.
I hope this answers all your questions.
Happy to help.
Hi @nunowp
I’m marking this topic as “resolved” due to recent inactivity. If more assistance is needed, feel free to post back here or open a new topic.
Thanks!
- The topic ‘Price display suffix not showing with same price variations’ is closed to new replies.