Skip Navigation

[Resolved] WooCommerce _sale_price_dates_to renderd as a long number on frontend

This thread is resolved. Here is a description of the problem and solution.

Problem:
How to display timestamp stored in _sale_price_dates_to WooCommerce custom field into desired date format

Solution:
You should create a custom shortcode and pass the time stamp to value to it and return the date with your desired format.

You can find proposed solution, in this case, with the following reply:
https://toolset.com/forums/topic/woocommerce-_sale_price_dates_to-renderd-as-a-long-number-on-frontend/#post-915109

Relevant Documentation:

This support ticket is created 5 years, 11 months ago. There's a good chance that you are reading advice that it now obsolete.

This is the technical support forum for Toolset - a suite of plugins for developing WordPress sites without writing PHP.

Everyone can read this forum, but only Toolset clients can post in it. Toolset support works 6 days per week, 19 hours per day.

No supporters are available to work today on Toolset forum. Feel free to create tickets and we will handle it as soon as we are online. Thank you for your understanding.

Sun Mon Tue Wed Thu Fri Sat
- 10:00 – 13:00 10:00 – 13:00 10:00 – 13:00 10:00 – 13:00 10:00 – 13:00 -
- 14:00 – 18:00 14:00 – 18:00 14:00 – 18:00 14:00 – 18:00 14:00 – 18:00 -

Supporter timezone: Asia/Kolkata (GMT+05:30)

This topic contains 8 replies, has 2 voices.

Last updated by Nashaat 5 years, 11 months ago.

Assisted by: Minesh.

Author
Posts
#914936

hi,
I have added following shortcode to Layout

[wpv-post-field name='_sale_price_dates_to']

the field renders long number instead date on the front end.

I have added this function to Code Snippet but this didnt help

function offer_end_date( $atts ){
  global $post;
  $sales_price_to = get_post_meta($post->ID, '_sale_price_dates_to', true);
  $sales_price_date_to = date("j M y", $sales_price_to);
  return $sales_price_date_to;
}
add_shortcode( 'end_date', 'offer_end_date' );

how can i fix this?

#915085

Minesh
Supporter

Languages: English (English )

Timezone: Asia/Kolkata (GMT+05:30)

Hello. Thank you for contacting the Toolset support.

Well - could you please tell me how and where you are using the custom shortcode you wrote.

It looks like field _sale_price_dates_to stores unix timestamp but I can guide you in right direction if you can share problem URL and access details with me.

*** Please make a FULL BACKUP of your database and website.***
I would also eventually need to request temporary access (WP-Admin and FTP) to your site. Preferably to a test site where the problem has been replicated if possible in order to be of better help and check if some configurations might need to be changed.

I would additionally need your permission to de- and re-activate Plugins and the Theme, and to change configurations on the site. This is also a reason the backup is really important. If you agree to this, please use the form fields I have enabled below to provide temporary access details (wp-admin and FTP).

I have set the next reply to private which means only you and I have access to it.

#915109

Minesh
Supporter

Languages: English (English )

Timezone: Asia/Kolkata (GMT+05:30)

Could you please check now.

I've added the following code to your code snippet:
=> hidden link

function func_offer_end_date( $atts ){
  global $post;
  $sales_price_to = get_post_meta($post->ID, '_sale_price_dates_to', true);
  $sales_price_date_to = date("j M y", $sales_price_to);
  return $sales_price_date_to;
}
add_shortcode( 'display_end_date', 'func_offer_end_date' );

And then with layout's cell - I've called the above shortcode as given under:

[display_end_date]

And now I can see the date is displaying with format you set:
=> hidden link

Could you please confirm it works at your end as well.

#915116

ok now i can see clearly a date but not the same date of woocommerce sale_date_to
in the product we have 28-06-2018
on the front end 27-6-2018

I have added another code for start date also and work the same as end date:
in the product we have 14-06-2018
on the front end 13-6-2018

function func_offer_end_date( $atts ){
  global $post;
  $sales_price_to = get_post_meta($post->ID, '_sale_price_dates_to', true);
  $sales_price_date_to = date("j M y", $sales_price_to);
  return $sales_price_date_to;
}
add_shortcode( 'display_end_date', 'func_offer_end_date' );

function func_offer_start_date( $atts ){
  global $post;
  $sales_price_from = get_post_meta($post->ID, '_sale_price_dates_from', true);
  $sales_price_date_from = date("j M y", $sales_price_from);
  return $sales_price_date_from;
}
add_shortcode( 'display_start_date', 'func_offer_start_date' );
#915121

Update:
when the product is submitted with Cred form, the right dates show up.
Product form : hidden link

but when the product submitted via WordPress dashboard and woocommerce the date show up wrong.

#915144

Minesh
Supporter

Languages: English (English )

Timezone: Asia/Kolkata (GMT+05:30)

Well - what if you change the timezone setting at: Settings => General => Timezone and set it to UTC+0 and save the setting.

After that try to create a new product and assign a date and try to display it - does that work?

#915233

Minesh you are a Genius! Thank you for your help, you always solve issues.

#915235

Minesh
Supporter

Languages: English (English )

Timezone: Asia/Kolkata (GMT+05:30)

Well - would you mind to resolve the ticket with happy face and feel free to share your feedback whatever you experience 🙂

#915239

Sure. Resolved and left a feedback for your awesome help!

This ticket is now closed. If you're a Toolset client and need related help, please open a new support ticket.