简体   繁体   中英

Woocommerce's functions shortcode

Let's say I want render some element of single product page of woocommerce, on any other page in wordpress exactly the same way. I would like just put a shortcode with a product ID on my page and for example product gallery will render. The problem is that I don't understand PHP in fact but I don't give up.

I figured out that it is possible create a custom function in the file functions.php located in my child theme...

function my_function() {
   return 'Hello!!';
}

...and then put my shortcode

add_shortcode('my_shortcode', 'my_function');

The question is How can I put into body of my function a method used by woocommerce? I guess, for this case it is following:

wordpress\wp-content\plugins\woocommerce\templates\single-product\product-image.php

Thanks for help!

WooCommerce already has this shortcode available:

[product id="99"]
[product sku="FOO"]

Please refer to the documentation for more information https://docs.woocommerce.com/document/woocommerce-shortcodes/

Also, if you need this in a template, you can simply add:

echo do_shortcode('[product sku="FOO"]');

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM