Home › Forums › WoodMart support forum › % discount Option
% discount Option
- This topic has 14 replies, 2 voices, and was last updated 10 months, 2 weeks ago by Aizaz Imtiaz Awan.
-
AuthorPosts
-
December 20, 2023 at 4:34 am #523127
shabeeronyxParticipantHi, there
I want add the % discount option to my product page, how its possible?Regards
Attachments:
You must be logged in to view attached files.December 20, 2023 at 3:08 pm #523323
Aizaz Imtiaz AwanKeymasterHello,
Try to add the following PHP code in the function.php of the child theme.
add_filter( 'woocommerce_get_price_html', 'change_displayed_sale_price_html', 10, 2 ); function change_displayed_sale_price_html( $price, $product ) { // Only on sale products on frontend and excluding min/max price on variable products if( $product->is_on_sale() && ! is_admin() && ! $product->is_type('variable')){ // Get product prices $regular_price = (float) $product->get_regular_price(); // Regular price $sale_price = (float) $product->get_price(); // Active price (the "Sale price" when on-sale) // "Saving Percentage" calculation and formatting $precision = 1; // Max number of decimals $saving_percentage = round( 100 - ( $sale_price / $regular_price * 100 ), 1 ) . '%'; // Append to the formated html price $price .= sprintf( __('<p class="saved-sale">off: %s</p>', 'woocommerce' ), $saving_percentage ); } return $price; }
Best Regards.
December 21, 2023 at 3:55 pm #523738
shabeeronyxParticipantYes It works, thanks but I need the letter colour to red and bold also make little larger
regards
December 22, 2023 at 9:27 am #523905
Aizaz Imtiaz AwanKeymasterHello,
Can you please share the WP admin login details of your site so I will check and give you the possible solution.
Best Regards.
December 22, 2023 at 3:36 pm #524036
shabeeronyxParticipantYaa sure
December 23, 2023 at 9:18 am #524185
Aizaz Imtiaz AwanKeymasterHello,
Please use the below custom CSS code and paste it to Theme Options >> Custom Code >> Global CSS code section:
.single-product p.saved-sale { font-weight: bold; color: red; }
Best Regards.
December 23, 2023 at 1:25 pm #524215
shabeeronyxParticipantThank you…
but one problem still exists the % does not round off itself, please look the imagesAttachments:
You must be logged in to view attached files.December 23, 2023 at 1:33 pm #524221
shabeeronyxParticipantAlso, I have another issue of the variation image size on my home page it’s too small to understand
Attachments:
You must be logged in to view attached files.December 23, 2023 at 4:56 pm #524253
Aizaz Imtiaz AwanKeymasterHello,
01. What do you mean round off? If you want to add any character you can edit the php code.
02. Please try to use the below custom CSS code and paste it to Theme settings >> Custom CSS >> Global CSS code section:
.wd-swatches-grid:is(.wd-size-xs,.wd-size-default) { --wd-swatch-size: 40px; }
Best Regards.
December 23, 2023 at 10:24 pm #524278
shabeeronyxParticipant01. What do you mean round off? If you want to add any character you can edit the php code.
ans. I just want to show a round off figure. now showing like 26.2% for this I want to round off this to just 26%
also I want variation swatches with image please check the screen shot
Attachments:
You must be logged in to view attached files.December 25, 2023 at 9:46 am #524381
Aizaz Imtiaz AwanKeymasterHello,
01. Unfortunately, Such modification requires complicated Woocommerce code customization which is not covered by our support.
02. Please check this manual to configure images in attributes: https://xtemos.com/docs-topic/variable-products-and-swatches/
Best Regards.
December 25, 2023 at 2:51 pm #524483
shabeeronyxParticipantIt’s ok, thank you
but the % issue still exist..aslo it does not show all my productsregards
Attachments:
You must be logged in to view attached files.December 26, 2023 at 8:36 am #524577
Aizaz Imtiaz AwanKeymasterHello,
Try to add the following PHP code in the function.php of the child theme.
// For product variations add_filter( 'woocommerce_available_variation', 'custom_variation_price_saving_percentage', 10, 3 ); function custom_variation_price_saving_percentage( $data, $product, $variation ) { $active_price = $data['display_price']; $regular_price = $data['display_regular_price']; if( $active_price !== $regular_price ) { $saving_percentage = round( 100 - ( $active_price / $regular_price * 100 ), 1 ) . '%'; $data['price_html'] .= sprintf( __('<p class="saved-sale">Save: %s</p>', 'woocommerce' ), $saving_percentage ); } return $data; } // For simple products add_filter( 'woocommerce_get_price_html', 'change_displayed_sale_price_html', 10, 2 ); function change_displayed_sale_price_html( $price, $product ) { // Only on sale products on frontend and excluding min/max price on variable products if( $product->is_on_sale() && ! is_admin() && $product->is_type('simple') ){ // Get product prices $regular_price = (float) $product->get_regular_price(); // Regular price $sale_price = (float) $product->get_price(); // Active price (the "Sale price" when on-sale) // "Saving Percentage" calculation and formatting $precision = 1; // Max number of decimals $saving_percentage = round( 100 - ( $sale_price / $regular_price * 100 ), $precision ) . '%'; // Append to the formated html price $price .= sprintf( __('<p class="saved-sale">Save: %s</p>', 'woocommerce' ), $saving_percentage ); } return $price; }
Best Regards.
December 26, 2023 at 3:36 pm #524646
shabeeronyxParticipantThank you for your help. The php code for product variations works but the % discount does not
regards
Attachments:
You must be logged in to view attached files.December 26, 2023 at 4:13 pm #524662
Aizaz Imtiaz AwanKeymasterHello,
Your issue has been resolved. Check back your site after completely clearing the browser cache.
Best Regards.
-
AuthorPosts
Tagged: discount
- You must be logged in to create new topics. Login / Register