I am looking for a way to pull(export) product post data (WooCommerce) using a shortcode by Product post ID to another general post
(ex. product post title/string).
Thank you
I am looking for a way to pull(export) product post data (WooCommerce) using a shortcode by Product post ID to another general post
(ex. product post title/string).
Thank you
Share Improve this question edited Mar 9, 2020 at 8:53 sleepingpanda 566 bronze badges asked Mar 8, 2020 at 18:10 LiorLior 11 Answer
Reset to default 0Add this code to your functions.php file and then you can use [product_title id="123"]
shortcode
If you want other product meta you can edit the function to return any product data you would want
/**
* Product title shortcode.
* `[product_title id="123"]` to get a specific product title, by ID
*
* @return string The post's title.
*/
add_shortcode( 'product_title', function( $atts ) {
$atts = shortcode_atts( array(
'id' => get_the_ID(),
), $atts, 'post_title' );
return get_the_title( absint( $atts['id'] ) );
});