Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Display woocommerce sale end date

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

but when I tried it, it did not work. Perhaps because the answer was too old.

Anyone knows how to get end date of scheduled sale woocommerce product?

This is what I have so far

$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;

it returns

string(0) ""

Thanks

like image 778
Wayne Avatar asked Dec 14 '22 23:12

Wayne


1 Answers

An example on this page, details how it can be done:
Add the following to the functions.php file

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 );
    }
}

I have tried it on my website and it works for me.

like image 196
Howli Avatar answered Dec 31 '22 03:12

Howli