Open bobbingwide opened 1 year ago
According to the documentation in https://woocommerce.com/document/related-products-up-sells-and-cross-sells/
Related products are displayed in response to the woocommerce_after_single_product_summary
action hook,
which is normally invoked in content-single-product.php
/**
* Hook: woocommerce_after_single_product_summary.
*
* @hooked woocommerce_output_product_data_tabs - 10
* @hooked woocommerce_upsell_display - 15
* @hooked woocommerce_output_related_products - 20
*/
do_action( 'woocommerce_after_single_product_summary' );
?>
If you don't invoke the action hook then neither upsells nor related products will be displayed.
Related products can be removed
remove_action( 'woocommerce_after_single_product_summary', 'woocommerce_output_related_products', 20 );
Adding the do_action produces the following output for A test product 6 x 4 ft (ID 7982 )
This product has an up-sell of A test product 10 x 10ft.
It also has a cross-sell of Alton Evolution Four LT 4 x 4 ft Greenhouse, but cross-sells are not displayed.
There is already logic to control how related products are displayed.
add_filter( 'woocommerce_output_related_products_args', 'vgc_woocommerce_related_products_args' );
The theme's filter function sets the posts_per_page
to 3 and columns
to 3.
For up-sells the number of columns is 4.
Note: Product data tabs are not displayed since the theme contains logic to remove the product tabs.
The filter below is invoked by the standard WooCommerce template single-product\tabs\tabs.php
add_filter( 'woocommerce_product_tabs', 'woo_remove_product_tabs', 98 );
function woo_remove_product_tabs( $tabs ) {
unset( $tabs['description'] ); // Remove the description tab
unset( $tabs['reviews'] ); // Remove the reviews tab
unset( $tabs['additional_information'] ); // Remove the additional information tab
return $tabs;
The unwanted ticks can be removed by CSS.
Notes:
With some CSS adjustments the display can look like this.
This allows for 3 columns for both up-sells and related products.
One possible solution for the problem with displaying cross-sells for products in the cart ( issue https://github.com/bobbingwide/vgc/issues/38 ) is to remove cross-sells and up-sells But now we have a requirement to display other products on the single product page.
Cross-sells could be
Up sells could be
The up-sells would be displayed below the single product details.