• Resolved kristinubute

    (@kristinubute)


    Hi

    On my Woocommerce Product Single Product Page, I have the Product description etc. Then I have a CUSTOM TAB underneath, then the RELATED PRODUCTS.

    How can I MOVE the RELATED PRODUCTS to be ABOVE the CUSTOM TAB for Single Product and STRAIGHT UNDER THE PRODUCT “ADD TO CART” button ?

    Just needs to be moved up further …

    Thanks
    Kristin

Viewing 3 replies - 1 through 3 (of 3 total)
  • Hello @kristinubute!

    The “Related Products” section is automatically generated, and there is no setting to change its position.

    However, its position can be changed using hooks or template modifications. Using hooks, you can change the priority of this section to move it above the other sections.

    As an example, I was able to move the ‘Related Products’ section right below the ‘Add to Cart’ button using the following code snippet:

    remove_action('woocommerce_after_single_product_summary', 'woocommerce_output_related_products', 20);
    add_action('woocommerce_after_single_product_summary', 'woocommerce_output_related_products', 9);

    Screenshot of the output: https://d.pr/i/9hlMlQ

    Reference: https://wordpress.stackexchange.com/questions/298952/move-related-products-after-product-summary

    Note: You can use the ‘Code Snippets’ plugin to enter this code for your site’s frontend.

    Here is how I use this: https://d.pr/i/9XsOVr

    This hook code will change the ‘Related Products’ section’s position for all product types, not just simple products. If you wish to change the position only for Simple products, then this hook code needs to be modified to first detect the product type and run accordingly.

    Best!

    Thread Starter kristinubute

    (@kristinubute)

    HI

    Thanks for your reply and effort.

    OK I will try that.
    The client has just said they prefer it UNDER the Short Description instead of under Add to Cart.

    Could you help with the new Snippet for that please ?

    Thanks in advance!

    REgards
    Kristin

    Hello @kristinubute!

    To put the ‘Related Products’ section under the ‘Short Description’ area, you need to first remove the ‘Related Products’, and then append it to the ‘Short Description’ section using related products shortcode; code provided below:

    $product = wc_get_product( $product_id );
    if(isset($product)){
    	remove_action('woocommerce_after_single_product_summary', 'woocommerce_output_related_products', 20);
    
    	add_filter('woocommerce_short_description','ts_add_text_short_descr');
    	function ts_add_text_short_descr($description){
    	    $text='[related_products limit="3"]';
    	    return $description.$text;
    	}
    }

    The end result would be something like this: https://d.pr/i/DIYAkz

    This code affects both simple and variable product types.

    Best!

Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘How can I MOVE the RELATED PRODUCTS’ is closed to new replies.