I am new to WooCommerce and I am currently developing a new site using the plugin to display Courses that can be purchased. I have added some products (courses) and configured them to have variations based on an attribute of Date.
What I would like WooCommerce to do is use custom field(s) such as Duration and display this information somewhere on the page (preferably in description or additional information tab. I would like the information to change based on the product variation that has been selected (e.g. A course with a date of 01.04.2014 will have a different duration than one that starts on 01.05.2014)
I have so far managed to successfully add custom fields by putting code in functions.php to display and save the information in the admin section for each variation.
When attempting to display this information by editing either additional-information.php or variable.php, nothing is being returned/displayed.
I have tried the following code:
echo get_post_meta( $post->ID, '_variable_duration', true );
echo get_post_meta( $product->ID, '_variable_duration', true );
I know that the information is being stored correctly in the field _variable_duration as I have checked the meta data in the database.
I believe it is struggling to find the correct product variation id as when I echo $post->id in additional-information.php, I am given the Parent Product ID and not the currently selected variation ID.
I have tried the following code too but nothing is being returned:
$post_id = $variation->ID; echo $post_id;
I want the information to be displayed dynamically, in the way that the price is displayed dynamically (changing based on the variation selected). This must therefore be possible because you can have variable prices, weights, heights etc. displayed out of the box but how can this be achieved with custom fields?
- The topic ‘Display Custom Fields Variations’ is closed to new replies.