Need "Sale To Date" On Woo Commerce Category Page

I want to add the "sale to date" on my on-sale category page for each product.  I have put together this function but it doesn't seem to be getting any values so please tell me what is wrong.  My Woo Commerce version is 3.4.4

add_filter( 'get_date_on_sale_to', 'custom_price_html', 100, 2 );
function custom_price_html( $price, $product )
{
    global $post;
    $sales_price_to = get_post_meta($post->ID, $data['date_on_sale_to'], true);
    if(is_product_category( 'on-sale' ) && ($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 );
    }
}

Open in new window

sharingsunshineAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Adrian ThompsonConsultant for Website Development and Online MarketingCommented:
Your code on line 5 is not correct:
$sales_price_to = get_post_meta($post->ID, $data['date_on_sale_to'], true);

Open in new window


The $data array seems to be added in error (it is not defined) and the function "get_post_meta" expects a STRING value as the 2nd argument. Therefore, change the above line of code to:
$sales_price_to = get_post_meta($post->ID, 'date_on_sale_to', true);

Open in new window


This assumes that you have a custom field with the name:
date_on_sale_to
0
Adrian ThompsonConsultant for Website Development and Online MarketingCommented:
Let me know if this works. If it does not work, I will show you how to troubleshoot in order to find the incorrect code.
0
sharingsunshineAuthor Commented:
that didn't work and it isn't a custom field.  Please see screenshot

https://gyazo.com/88d817384008aa2938e04b6cb5594bbe
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
woo commerce

From novice to tech pro — start learning today.