Home › Forums › WoodMart support forum › Resolving Price Display Issues for Variable Products in WooCommerce: Fixing Sale
Resolving Price Display Issues for Variable Products in WooCommerce: Fixing Sale
- This topic has 7 replies, 2 voices, and was last updated 1 month ago by Luke Nielsen.
-
AuthorPosts
-
September 29, 2024 at 9:56 pm #601114
av_admin_1984ParticipantHi
We are using a code on our website that you previously developed to swap the display of the sale price and the regular price of a product. The issue with this code is that for variable products, it merges the regular price and the sale price into one. With this code, both output prices are the same, meaning the sale price and the regular price are identical. The code is as follows:
function custom_pric_sale_price_html( $price, $product ) { if ( $product->is_on_sale() ) { $regular_price = wc_get_price_to_display( $product, array( 'price' => $product->get_regular_price() ) ); $sale_price = wc_get_price_to_display( $product, array( 'price' => $product->get_sale_price() ) ); $price = '<del>' . wc_price( $regular_price ) . '</del> <br> <ins>' . wc_price( $sale_price ) . '</ins>'; } return $price; } add_filter( 'woocommerce_get_price_html', 'custom_pric_sale_price_html', 10, 2 );
I also found these codes but they don’t work
function custom_pric_sale_price_html( $price, $product ) { if ( $product->is_on_sale() ) { $regular_price = $product->get_regular_price(); $sale_price = $product->get_sale_price(); $regular_price_display = wc_get_price_to_display( $product, array( 'price' => $regular_price ) ); $sale_price_display = wc_get_price_to_display( $product, array( 'price' => $sale_price ) ); $price = '<del>' . wc_price( $regular_price_display ) . '</del> <br> <ins>' . wc_price( $sale_price_display ) . '</ins>'; } else { $regular_price_display = wc_get_price_to_display( $product, array( 'price' => $product->get_regular_price() ) ); $price = wc_price( $regular_price_display ); } return $price; } add_filter( 'woocommerce_get_price_html', 'custom_pric_sale_price_html', 10, 2 );
or
function custom_pric_sale_price_html( $price, $product ) { if ( $product->is_on_sale() ) { $regular_price = $product->get_regular_price(); $sale_price = $product->get_sale_price(); $regular_price_display = wc_get_price_to_display( $product, array( 'price' => $regular_price ) ); $sale_price_display = wc_get_price_to_display( $product, array( 'price' => $sale_price ) ); $price = '<del>' . wc_price( $regular_price_display ) . '</del> <br> <ins>' . wc_price( $sale_price_display ) . '</ins>'; } else { $regular_price_display = wc_get_price_to_display( $product, array( 'price' => $product->get_regular_price() ) ); $price = wc_price( $regular_price_display ); } return $price; } add_filter( 'woocommerce_get_price_html', 'custom_pric_sale_price_html', 10, 2 );
or
function custom_pric_sale_price_html( $price, $product ) { if ( $product->is_on_sale() ) { $regular_price = $product->get_regular_price(); $sale_price = $product->get_sale_price(); $regular_price_display = wc_get_price_to_display( $product, array( 'price' => $regular_price ) ); $sale_price_display = wc_get_price_to_display( $product, array( 'price' => $sale_price ) ); $price = '<del>' . wc_price( $regular_price_display ) . '</del> <br> <ins>' . wc_price( $sale_price_display ) . '</ins>'; } return $price; } add_filter( 'woocommerce_get_price_html', 'custom_pric_sale_price_html', 10, 2 );
or
function custom_pric_sale_price_html( $price, $product ) { if ( $product->is_on_sale() && $product->is_type('variable') ) { // Get the variation prices $regular_price = $product->get_regular_price(); $sale_price = $product->get_sale_price(); // Check if sale price and regular price are not the same if ( $regular_price !== $sale_price ) { $regular_price_display = wc_get_price_to_display( $product, array( 'price' => $regular_price ) ); $sale_price_display = wc_get_price_to_display( $product, array( 'price' => $sale_price ) ); $price = '<del>' . wc_price( $regular_price_display ) . '</del> <br> <ins>' . wc_price( $sale_price_display ) . '</ins>'; } else { // If they are the same
or
function custom_pric_sale_price_html( $price, $product ) { if ( $product->is_on_sale() && $product->is_type('variable') ) { $regular_price = $product->get_regular_price(); $sale_price = $product->get_sale_price(); if ( $regular_price !== $sale_price ) { $regular_price_display = wc_get_price_to_display( $product, array( 'price' => $regular_price ) ); $sale_price_display = wc_get_price_to_display( $product, array( 'price' => $sale_price ) ); $price = '<del>' . wc_price( $regular_price_display ) . '</del> <br> <ins>' . wc_price( $sale_price_display ) . '</ins>'; } else { $price = wc_price( wc_get_price_to_display( $product, array( 'price' => $regular_price ) ) ); } } return $price; } add_filter( 'woocommerce_get_price_html', 'custom_pric_sale_price_html', 10, 2 );
How can I resolve this issue?
September 30, 2024 at 5:33 pm #601424
Luke NielsenKeymasterHello,
Please send me the URL page where it merges the regular price and the sale price into one. Also, provide the admin access to that website so I can investigate it.
Kind Regards
September 30, 2024 at 10:35 pm #601462
av_admin_1984ParticipantHi
Please don’t change anything in this site,
Please don’t share anything hereJust put image in wordpress gallery and tell me
Thanks
October 1, 2024 at 4:36 pm #601739
Luke NielsenKeymasterHello,
Sorry for the delay.
It seems you sent the URL of the page via the tool for the URLs, unfortunately, that short URL is not working, may you send me the default URL?
Thank you for your time.
Kind Regards
October 1, 2024 at 7:23 pm #601782
av_admin_1984ParticipantHi
your support forum dos not support UTF8 url’s
Check private box
October 2, 2024 at 4:38 pm #602045
Luke NielsenKeymasterHello,
We see the problem, but this problem was caused by custom code that is only intended for simple products.
I await your response.
Kind Regards
October 2, 2024 at 6:00 pm #602074
av_admin_1984ParticipantHello
Do you have any suggestion or soulution?
I need that code to change the order of price for simple productand I also sent you the code that we compiled to work with variation product but did not work at all
do you have custom code for both of theme?
October 3, 2024 at 9:18 am #602139
Luke NielsenKeymasterHello,
Sorry but the 3rd party customization, including developing or modifying custom code, is not included in our support services.
For more advanced customizations like this, I would recommend consulting a WooCommerce developer who can assist in tailoring the code to meet your needs.
If you have any questions regarding the WoodMart theme features, feel free to reach out. We’re happy to help within the scope of our support.
Kind Regards
-
AuthorPosts
- You must be logged in to create new topics. Login / Register