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.
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/
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.
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>';'
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.
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.