• Hi there! I’m using a snippet that works great to show sale price dates on WooCommerce product page: https://unlimitedwp.com/ecommercehints/woocommerce-show-sale-price-dates-on-product-page/

    However i’m unable to add the same information to YITH Quick View, can someone help me?

    This is the code i’m using:

    /**
     * Snippet Name:	WooCommerce Display Sale Price Dates
     * Snippet Author:	ecommercehints.com
     */
    
    add_filter( 'woocommerce_get_price_html', 'ecommercehints_display_sale_price_dates', 100, 2 );
    function ecommercehints_display_sale_price_dates( $price, $product ) {
        $sales_price_from = get_post_meta( $product->id, '_sale_price_dates_from', true );
        $sales_price_to   = get_post_meta( $product->id, '_sale_price_dates_to', true );
        if ( is_product() && $product->is_on_sale() && $sales_price_to != "" ) {
            $sales_price_date_from = date( "l jS F", $sales_price_from );
            $sales_price_date_to   = date( "l jS F", $sales_price_to );
            $price .= "<br><small>Sale from " . $sales_price_date_from . ' to ' . $sales_price_date_to . "</small>";
    	}
        return $price;
    }

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

Viewing 4 replies - 1 through 4 (of 4 total)
  • Plugin Support Facundo Arano

    (@aranofacundo)

    Hi there,

    Our plugin uses its own template to display the product summary, the is_product() check prevents the code from being displayed in the quick view.

    You can try the following PHP code in the functions.php to display the sale dates in the quick view:

    if ( ! function_exists( 'yith_wcqv_custom_show_custom_product_price_html' ) ) {
    	add_action( 'yith_wcqv_product_summary', 'yith_wcqv_custom_show_custom_product_price_html', 14 );
    
    	function yith_wcqv_custom_show_custom_product_price_html() {
    		add_filter( 'woocommerce_get_price_html', 'ecommercehints_display_sale_price_dates2', 100, 2 );
    	}
    
    	function ecommercehints_display_sale_price_dates2( $price, $product ) {
    		$sales_price_from = get_post_meta( $product->id, '_sale_price_dates_from', true );
    		$sales_price_to   = get_post_meta( $product->id, '_sale_price_dates_to', true );
    		if ( $product->is_on_sale() && $sales_price_to != '' ) {
    			$sales_price_date_from = date( 'l jS F', $sales_price_from );
    			$sales_price_date_to   = date( 'l jS F', $sales_price_to );
    			$price                .= '<br><small>Sale from ' . $sales_price_date_from . ' to ' . $sales_price_date_to . '</small>';
    		}
    		return $price;
    	}
    }

    Let us know if this helped you.

    Thread Starter Filipe Costa

    (@filipecostacom)

    Hi and thanks!
    I’ve tried the PHP code but it doesn’t work – sale price dates are not shown on main product page nor on quick view.

    I’ve disabled my previous code and only used the one supplied here.

    Thanks!

    NOTE: Since the code doesn’t work i had to disabled it because i’m obliged by law to have the dates on the online store…

    Plugin Support Vanesa

    (@vanesarodriguez)

    Hi there,
    please, try your previous code but without the is_product() check that, as Facundo said, prevents the code to show the dates in the quickview:

    add_filter( 'woocommerce_get_price_html', 'ecommercehints_display_sale_price_dates', 100, 2 );
    function ecommercehints_display_sale_price_dates( $price, $product ) {
        $sales_price_from = get_post_meta( $product->id, '_sale_price_dates_from', true );
        $sales_price_to   = get_post_meta( $product->id, '_sale_price_dates_to', true );
        if ( $product->is_on_sale() && $sales_price_to != "" ) {
            $sales_price_date_from = date( "l jS F", $sales_price_from );
            $sales_price_date_to   = date( "l jS F", $sales_price_to );
            $price .= "<br><small>Sale from " . $sales_price_date_from . ' to ' . $sales_price_date_to . "</small>";
        }
        return $price;
    }

    Try it and let us know.
    We remain at your disposal.

    Thread Starter Filipe Costa

    (@filipecostacom)

    Hi again and thanks!

    I tried the new code, but it still doesn’t show on YITH WooCommerce Quick View…

    I only changed the date to d.m.Y because i prefer that way and translated the English descriptions.

    Here is a link to the sale page:
    https://filipecosta.com/loja/promocoes/
    where you can see one or more products on sale and try the YITH WooCommerce Quick View.

    Thanks!

Viewing 4 replies - 1 through 4 (of 4 total)
  • You must be logged in to reply to this topic.