I want to add on templates/content-single-product.php:
• An opening<div>before line 39
• A close</div>after line 81.
Copying this template to my active theme and make the customization just works fine.
However is there a better way to do this without copying the template?
I thought I had seen some way to apply a filter to do_action( 'woocommerce_before_single_product_summary' ); and do_action( 'woocommerce_after_single_product_summary' ); to do something similar. 
I just wanted to check the way I am doing, is the correct way.
Is the way I have chose, the right way?
Thanks.
In template content-single-product.php, The only way to have your open <div>, is the template herself, as you want it before (line 39):
<div itemscope itemtype="<?php echo woocommerce_get_product_schema(); ?>" id="product-<?php the_ID(); ?>" <?php post_class(); ?>>
Because if you use woocommerce_before_single_product_summary your open <div> is going to be after that existing <div itemscope itemtype="…"> and not before.
For the closing , as you are editing your template, the best way is to add it in your template (just as you made it.
But it should work too in woocommerce_after_single_product hook with any kind of priority (as nothing is already hooked in); this way for example:
function single_product_closing_div(){
    echo '</div>';
}
add_action( 'woocommerce_after_single_product', 'single_product_closing_div', 10, 0 );
Conclusion: You have done it the right way, in the template directly.
You can probably do that by adding two hooks for woocommerce_before_single_product_summary and woocommerce_after_single_product_summary so they will look like this
add_action('woocommerce_before_single_product_summary','your_function_name',1); add_action('woocommerce_after_single_product_summary','another_function_name',99); function your_function_name(){echo ""; } function another_function_name(){echo ""; }
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With