• Hello,
    I am trying to insert by jQuery what gives the user more information about the discount he has in a variable product.

    I made a function that improve the class woocommerce-variation-price. It works well in the product pages, but not in the WPC QuickView. Here is the function :

    
    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 price" calculation and formatting
            $saving_price = wc_price( $regular_price - $sale_price );
    
            // "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">I am saving %s <em>(%.2s <span>%</span> of discount)</em></p>', 'woocommerce' ), $saving_price, $saving_percentage );
        }
        return$price;	
    }
    

    In few words, I would like to have in the QuickView what returns the sprintf function.
    It is difficult for me because I don’t know how to manage something dynamic in jQuery. Could I in some ways :

    jQuery(document.body).on('woosq_loaded', function() {
       	jQuery("#woosq-popup .woovr-variation-price").append(jQuery( ?FUNCTION? ));
    });
    • This topic was modified 3 years, 3 months ago by sna1234.

    The page I need help with: [log in to see the link]

Viewing 1 replies (of 1 total)
  • Plugin Author WPClever

    (@wpclever)

    Hi @sna1234

    Our plugin using admin AJAX, so you just need to change the conditional:

    if ( $product->is_on_sale() && ! ( is_admin() && ! wp_doing_ajax() ) && ! $product->is_type( 'variable' ) ) {
    ...
    }

    It will work fine for both the single product page and the quick view popup.

Viewing 1 replies (of 1 total)
  • The topic ‘Add saved_sale for variable product’ is closed to new replies.