what is the shortcode for woocommerce product content?

I searched everywhere and could not find a shortcode for the product content area of woocommerce, it's available in elementor as a widget but what about a shortcode ?

Solutions

You have to create product content shortcode by product id.

Now I have created a shortcode for you like this:

function woo_product_details($atts = array()){
   if(isset($atts['product_id']) && !empty($atts['product_id'])){
        $html = '';
        $product_id                = $atts['product_id'];
        $product                   = wc_get_product($product_id);

        $product_name              = $product->get_name();
        $product_slug              = $product->get_slug();
        //$product_sku               = $product->get_sku();
        //$product_description       = $product->get_description();
        $product_short_description = $product->get_short_description(); 
        //$product_price             = $product->get_price();
        $product_formated_price    = $product->get_price_html();
        //$product_regular_price     = $product->get_regular_price();
        //$product_sale_price        = $product->get_sale_price();  
        $product_image= wp_get_attachment_image_src( get_post_thumbnail_id($product_id), 'single-post-thumbnail' );
        
        $html .= '<div class="card">
            <img src="'.$product_image[0].'" alt="'.$product_name.'" data-id="'.$product_id.'" style="width:100%">
            <h1>'.$product_name.'</h1>
            <p class="price">'.$product_formated_price.'</p>
            <p>'.$product_short_description.'</p>
            <p><a href="'.site_url().'?add-to-cart='.$product_id.'&quantity=1">Add to Cart</a></p>
        </div>';
        return $html;
    }
}
add_shortcode('product_detail', 'woo_product_details');

You can add/ update HTML and product info accordingly, If you want to get another product variable to set/change from an existing function show should check https://www.businessbloomer.com/woocommerce-easily-get-product-info-title-sku-desc-product-object/ and copy page accordingly on given shortcode function.

How to User shortcode

a) You can call directly on your PHP page like this:

<?php echo do_shortcode('[product_detail product_id = '1002']'); ?>

b) You can call on your post and page from admin panel like this:

[product_detail product_id = '1002']

Where 1002 is product id

Similar questions

Show WooCommerce product tag name set for a product with a shortcode
As the title says I’m looking for a shortcode I can use to show the tag of a specific product. All my products have only one product tag set for each. For example, if the product with ID: 1250 has the tag “Horse” I need the way to put a shortcode specifying the ID of the product and show your respective tag. In the example the shortcode should show...
Post loop created via shortcode not displaying shortcode in content
I've been racking my brain on this. Here is a shortcode loop I've created to display a specific post type: within one of those loops there is a post that has a shortcode being used the FAQ loop (code item #1) isn't parsing the shortcode. It just displays it raw.
Getting shortcode attribute values and shortcode content with JavaScript regex
This is an example shortcode: I have created a custom mce view to display this shortcode nicely in the backend editor. Now I'm working on the "edit" button when this shortcode is clicked. I am trying to get all the attributes and the shortcode content, so I can display them when doing editor.windowManager.open This is the working regex I have for g...
Shortcode content is not showing. Only the [shortcode-tag] is showing
I am creating a small plugin where I am creating a few shortcodes. I am using Classic Editor plugin. Here is my code in Plugin.php: But when I put the shortcode in Post content as [dream-big], it is only rendering the tag, i.e. [dream-big] on post page rather than showing its content: Hello! Can you dream big? I also took a different approach: But ...
Using shortcode content with nested shortcode
This is a shortcode example. It should be used like this with do_shortcode($content); Is there a reason you dont use content without do_shortcode?
Shortcode not appearing when used as post content in wp_insert_post() or possibly, shortcode not being registered at all
I have a plugin which creates a page upon activation and then removes it on deactivation. As part of the page creation, I wanted to use a shortcode in the post content, so I added a shortcode with add_shortcode() first. For debug purposes, I immediately test the shortcode with shortcode_exists() and print out an appropriate log statement. The logs ...

Also ask

We use cookies to deliver the best possible experience on our website. By continuing to use this site, accepting or closing this box, you consent to our use of cookies. To learn more, visit our privacy policy.