WordPress.org

Ready to get started?Download WordPress

Forums

WooCommerce - excelling eCommerce
Display Sale End date in single product page (2 posts)

  1. janmalagucute
    Member
    Posted 3 months ago #

    Hi,

    I found this similar question
    http://wordpress.org/support/topic/get-woocommerce-scheduled-sale-end-date?replies=15

    but the solutions provided seems outdated.

    I tried to use this
    $sale_price_dates_to = ( $date = get_post_meta( $thepostid, '_sale_price_dates_to', true ) ) ? date_i18n( 'Y-m-d', $date ) : '';
    echo $sale_price_dates_to;

    but it returns

    string(0) ""

    Anyone know how is the updated way of displaying end date of sale product in single product page?

    Thanks

    https://wordpress.org/plugins/woocommerce/

  2. terrytsang
    Member
    Posted 3 months ago #

    Hi @janmalagucute, you can add below code to functions.php in your theme folder:

    add_filter( 'woocommerce_get_price_html', 'custom_price_html', 100, 2 );
    function custom_price_html( $price, $product ){
        global $post;
        $sales_price_to = get_post_meta($post->ID, '_sale_price_dates_to', true);
        if(is_single() && $sales_price_to != "")
        {
            $sales_price_date_to = date("j M y", $sales_price_to);
    
            return str_replace( '</ins>', ' </ins> <b>(Offer till '.$sales_price_date_to.')</b>', $price );
        }
        else
        {
            return apply_filters( 'woocommerce_get_price', $price );
        }
    }

Reply

You must log in to post.

About this Plugin

About this Topic