Home » WooCommerce: Related Products in a Tab on the Product Page

WooCommerce: Related Products in a Tab on the Product Page

by adminkys

This is a simple snippet that will allow you to move the Related Products from below the tabs to inside the single product tabs, in a brand new tab.

WooCommerce Related Products Tab
WooCommerce Related Products Tab

PHP Snippet: Move Related Products to a Tab – WooCommerce

/**
 * @snippet       Checkbox to display Custom Product Badge Part 1 - WooCommerce
 * @how-to        Get tutoraspire.com FREE
 * @source        https://tutoraspire.com/?p=17419
 * @author        Tutor Aspire
 * @compatible    Woo 3.5.3
 * @donate $9     https://www.tutoraspire.com
 */

// First, let's remove related products from their original position

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

// Second, let's add a new tab

add_filter( 'woocommerce_product_tabs', 'woo_new_product_tab' );

function woo_new_product_tab( $tabs ) {

$tabs['related_products'] = array(
'title' => __( 'Try it with', 'woocommerce' ),
'priority' => 50,
'callback' => 'woo_new_product_tab_content'
);
return $tabs;
}

// Third, let's put the related products inside

function woo_new_product_tab_content() {
woocommerce_output_related_products();
}

You may also like