Reputation: 13
I have a child theme from Storefront and have custom page templates running for the homepage and other pages without issues.
I am building a custom layout for Woocommerce pages and use content-single-product.php
for the single product page with custom code in the file for example:
<div class="wc-product-images">
<?php do_action( 'woocommerce_before_single_product_summary', 'woocommerce_show_product_images'); ?>
</div>
<div class="wc-product-description">
<?php the_content(); ?>
</div>
Question 1: Do I call the Woocommerce Content correct with do_action()
in the template file? I have a specific layout and cannot follow the hook layouts as per the default file
Question 2: When I call:
<?php
do_action( 'woocommerce_after_single_product_summary', 'woocommerce_output_related_products' );
?>
I get the product description with the related products and actually need to build a div with only related products.
How can I call this properly without the description included?
Any help is appreciated.
Upvotes: 1
Views: 2314
Reputation: 253784
You are making confusions, original do_action( 'woocommerce_before_single_product_summary' )
enables an entry point in woocommerce content-single-product.php
template, where add_action()
is used to hook other templates using the functions:
woocommerce_show_product_sale_flash()
(with a hook priority of 10)woocommerce_show_product_images()
(with a hook priority 20)So if you want to enable only the product image in your custom template you will have to create your own hook:
<div class="wc-product-images">
<?php do_action( 'woocommerce_before_single_product_summary_custom' ); ?>
</div>
<div class="wc-product-description">
<?php the_content(); ?>
</div>
Then you will add this in function.php file of your active child theme (or active theme):
add_action( 'woocommerce_before_single_product_summary_custom', 'woocommerce_show_product_images', 20 );
It should work as intended.
But you can use in your custom template the original hook, if you don't need any different hook customizations… In that case you will only have that:
<div class="wc-product-images">
<?php do_action( 'woocommerce_before_single_product_summary' ); ?>
</div>
<div class="wc-product-description">
<?php the_content(); ?>
</div>
Additon: Related to your comment (regarding related products).
To enable related products in your custom template, add this block in it (with a custom hook):
<div class="wc-product-related">
<?php do_action( 'custom_after_single_product_summary' ); ?>
</div>
Then you will add this in function.php file of your active child theme (or active theme):
add_action( 'custom_after_single_product_summary', 'woocommerce_output_related_products', 20 );
It should work.
Upvotes: 0