Home Forums WoodMart support forum % discount Option

% discount Option

Viewing 15 posts - 1 through 15 (of 15 total)
  • Author
    Posts
  • #523127

    shabeeronyx
    Participant

    Hi, 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.
    #523323

    Hello,

    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.

    #523738

    shabeeronyx
    Participant

    Yes It works, thanks but I need the letter colour to red and bold also make little larger

    regards

    #523905

    Hello,

    Can you please share the WP admin login details of your site so I will check and give you the possible solution.

    Best Regards.

    #524036

    shabeeronyx
    Participant

    Yaa sure

    #524185

    Hello,

    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.

    #524215

    shabeeronyx
    Participant

    Thank you…
    but one problem still exists the % does not round off itself, please look the images

    Attachments:
    You must be logged in to view attached files.
    #524221

    shabeeronyx
    Participant

    Also, 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.
    #524253

    Hello,

    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.

    #524278

    shabeeronyx
    Participant

    01. 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.
    #524381

    Hello,

    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.

    #524483

    shabeeronyx
    Participant

    It’s ok, thank you
    but the % issue still exist..aslo it does not show all my products

    regards

    Attachments:
    You must be logged in to view attached files.
    #524577

    Hello,

    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.

    #524646

    shabeeronyx
    Participant

    Thank 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.
    #524662

    Hello,

    Your issue has been resolved. Check back your site after completely clearing the browser cache.

    Best Regards.

Tagged: 

Viewing 15 posts - 1 through 15 (of 15 total)