Skip Navigation

[Resolved] Adding data render field to PHP line

The Toolset Community Forum is closed, for technical support questions, please head on to our Toolset Professional Support (for paid clients), with any pre-sale or admin question please contact us here.
This support ticket is created 9 years, 7 months ago. There's a good chance that you are reading advice that it now obsolete.
This is the community support forum for Types plugin, which is part of Toolset. Toolset is a suite of plugins for developing WordPress sites without writing PHP.

Everyone can read this forum, but only Toolset clients and people who registered for Types community support can post in it.

Sun Mon Tue Wed Thu Fri Sat
- 9:00 – 13:00 9:00 – 13:00 9:00 – 13:00 9:00 – 13:00 9: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/Hong_Kong (GMT+08:00)

Tagged: 

This topic contains 6 replies, has 2 voices.

Last updated by vytenisK 9 years, 7 months ago.

Assisted by: Luo Yang.

Author
Posts
#235415

Okay, I'm using woocommerce and trying to get it so the user can add a date (via Types- pref. in MM/DD format) and have it display in the backorder message. Here is the woocommerce code:

if ( $_product->backorders_require_notification() && $_product->is_on_backorder( $cart_item['quantity'] ) )
          echo '<p class="backorder_notification">' . __( 'Available on backorder till DATE ;<br /> will call when it comes in', 'woocommerce' ) . '</p>';

I want to replace 'DATE' with the actual date the user inputted. Is there actually a way to do that? The php file is one of the default woocommerce php files.

#235676

Hi vytenisK,

Please Types function types_render_field(), for example:

if ( $_product->backorders_require_notification() && $_product->is_on_backorder( $cart_item['quantity'] ) )
          echo '<p class="backorder_notification">Available on backorder till' . types_render_field( "my-date", array( 'format'=> 'm/d') )  . '<br /> will call when it comes in '</p>';

Please replace "my-date" with your custom field slug

More help:
Displaying WordPress Custom Fields
https://toolset.com/documentation/user-guides/displaying-wordpress-custom-fields/

#239906

Thanks for the assistance, but it doesn't print out a date. I don't get any errors when loading the page, but no date is listed.

#239907

Okay, instead of the date (I am running into a bug with the date picker), I'm gonna use the single line field. Would this be the code?

'if ( $_product->backorders_require_notification() && $_product->is_on_backorder( $cart_item['quantity'] ) )
echo '<p class="backorder_notification"> Available on backorder until' . types_render_field( "backorder-date", array( 'format'=> 'm/d') ) . '<br /> will call when it comes in </p>';'

#239909

Sorry, supposed to read

types_render_field( "slug", array( )
#240155

Please try add parameter in function types_render_field(), like this:

...
 types_render_field( "backorder-date", array( 'format'=> 'm/d', 'post_id'=> $_product->id))
...

And the "format" only works for Types date field, So I still suggest you setup the backorder-date as a date field.

#240451

Great, that worked. I am having problems with the data type; when I choose a date with the picker, I can never delete that date, only change it. I decided to try a single line field so the user could either enter it as MM/YY or M/D/Y.

The forum ‘Types Community Support’ is closed to new topics and replies.

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