skip to Main Content

I need to show the summary of a single product on the front-page of my WordPress/WooCommerce Template. So on the front-page.php i want to use the following action:

 do_action( 'woocommerce_single_product_summary' );

How can i reference this to the product id with the product-id 150?

2

Answers


  1. These kind of Woo actions work based on global $product variable.
    So you can try something like this:

    global $product;
    
    //first check if the object already exists and store its original value
    $reserve_product='';
    if(!empty($product))$reserve_product=$product;
    
    //now change global $product value to the desired one
    $product=wc_get_product(150);
    
    do_action( 'woocommerce_single_product_summary' );
    
    //return the previous value
    $product=$reserve_product;
    
    Login or Signup to reply.
  2. To show the single product summary please use this code

    //as you register a custom hook called woocommerce_single_product_summary
    add_action('woocommerce_single_product_summary', 'get_product_summary')
    
    function get_product_summary(){
       $product = wc_get_product( $product_id );
       
       if($product){
          $product_details = $product->get_data();
    
          //for full summary
          $product_full_description  = $product_details['description'];
       
          //for short summary
          $product_short_description = $product_details['short_description'];
          echo '<p>'.$product_short_description '</p>';
       }
    }
    
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search