Hello,
and Thanks very much for your tutorial to learn "how to add e-commerce functionality to any WordPress site using Toolset"
In this tutorial and in your discover-wp.com demo, your sample code is a view template to display woo commerce single product type
How can we create a view template to display variable product (including displaying select fields on front end for variable attributes like a color choice for the product before displaying the price corresponding ) ?
Dear Cheikhna,
WooCommerce templates work with action hooks. These actions, when called, include the necessary code to render the dropdowns and so on. You wont be able to go that far with a Content Template because there is no way to run an action from it.
For example, the default WooCommerce template includes this line to render the dropdown:
do_action( 'woocommerce_single_product_summary' );
We cant run that code from within a Content Template, so we have to turn it into a shortcode. Add these lines to functions.php in your theme:
add_shortcode('do-action', 'do_action_shortcode');
function do_action_shortcode($atts, $content = '') {
ob_start();
do_action($content);
$out = ob_get_contents();
ob_end_clean();
return $out;
}
And include this code in your Content Template to show the product summary:
[do-action]woocommerce_single_product_summary[/do-action]
Please let me know if there is anything else that I can assist you with.
Regards,
Caridad