I want to seperate tabs and related products, so I used:

remove_action( 'woocommerce_after_single_product_summary', 'woocommerce_output_related_products', 20 );
do_action( 'woocommerce_after_single_product_summary' );

This code worked well, but i want to add related products again to the single product page.

How can I add related products only?

Thank you.

  • Please take your time, use the WYSIWYG editor buttons to format code, use proper upper- and lowercase characters, etc. Thanks. – kaiser Sep 26 '13 at 20:15

Remove the action from it's hook, then add it to a different hook (corresponding to where you'd like it to display). You can view the available hooks by viewing the WooCommerce single-product.php and content-single-product.php template files. Just like it all of WordPress anywhere there is a do_action( 'some_hook_name' ) that signifies an action hook that you can attach functions to. Here is an example (for your functions.php) that will move the related products output to outside the #product div.

function wpa_115808(){
   remove_action( 'woocommerce_after_single_product_summary', 'woocommerce_output_related_products', 20 );
   add_action( 'woocommerce_after_single_product', 'woocommerce_output_related_products' );
add_action( 'woocommerce_before_main_content', 'wpa_115808' );

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.