bobbingwide / vgc

VGC - Garden Vista Group theme
GNU General Public License v2.0
0 stars 0 forks source link

Single Product display - Add support for Cross sells or Up sells #54

Open bobbingwide opened 1 year ago

bobbingwide commented 1 year ago

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.

The up-sells would be displayed below the single product details.

bobbingwide commented 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 );
bobbingwide commented 1 year ago

Adding the do_action produces the following output for A test product 6 x 4 ft (ID 7982 )

image

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.

bobbingwide commented 1 year ago

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.

bobbingwide commented 1 year ago

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;
bobbingwide commented 1 year ago

The unwanted ticks can be removed by CSS.

image

Notes:

bobbingwide commented 1 year ago

With some CSS adjustments the display can look like this.

image

This allows for 3 columns for both up-sells and related products.