Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to display a single variable product page on homepage in Woocommerce

In Woocommerce I have a single variable product set with different attributes. I can see the product like the following image (without its attributes variations), in archive pages as shop:

enter image description here

When I see this product in it single product page, I am able to see the following details:

enter image description here

So I will like to see all details on the homepage so that the buyer can select their variation and add to cart without opening further into the product.

I have tried to edit the woocommerce single-product.php file but i didn't get it working.

Is there a way to get those the full details?

Any help is appreciated.

like image 746
Tata Avatar asked Aug 19 '18 09:08

Tata


People also ask

How do I display a variable product in WooCommerce?

Go to: WooCommerce > Products. Select the Add Product button or Edit an existing product. The Product Data displays. Select Variable product from the Product Data dropdown.

How do I show a specific category product in my home page?

Show Product Categories on Shop PageClick on Appearance > Customize. Then go to WooCommerce > Product Catalog. Select “Show categories” from Shop Page Display. Click on Save Changes.


1 Answers

If you want to display a "detailed" variable product (as in it's single product page) on your home page, you need to:

  1. Create a simple Wordpress page and make it your home page.
  2. In that page, within the Wordpress content text editor, you will paste a woocommerce shortcode. In this shortcode you will set the correct post ID (or product Id) corresponding to the desired product to be displayed like in the example below:

    [product_page id="99"]
    

Now you will have the detailed product in your home page.


You may need to remove from this page some non desired details as the product tabs, the related products and some other things.

If you look to the single-content-product.php woocommerce template you will see that all sections are "hooked" (added) to the product page.

You can remove some using for example the following example that will remove:

  • the product tabs section
  • The upsells section
  • The related products section

Here is that code example:

add_action( 'template_redirect', 'remove_after_single_product_section_on_home', 1 );
function remove_after_single_product_section_on_home(){

    // On home page only
    if( is_front_page() ) {
        remove_action( 'woocommerce_after_single_product_summary', 'woocommerce_output_product_data_tabs', 10 ); // Product tabs
        remove_action( 'woocommerce_after_single_product_summary', 'woocommerce_upsell_display', 15 ); // Upsells
        remove_action( 'woocommerce_after_single_product_summary', 'woocommerce_output_related_products', 20 ); // Related products
    }
}

Code goes in function.php file of your active child theme (or active theme). Tested and works.

enter image description here

like image 186
LoicTheAztec Avatar answered Oct 21 '22 15:10

LoicTheAztec