-1

I am trying to build custom shortcodes for wordpress / WooCommerce, so that I can select just the image or just the price of one single product, because I want to style the product page, but I can't do that with the shortcodes that made by themself...

I have looked alot on google, tryed multiple codes en previeuws but no succes :(

Maybe someone who can help my out??

This is what I have now and this works so far!!

//Select just one img from a WooCommerce product.
function singleProduct_img( $atts ) {

    $a = shortcode_atts( array(
       'product_id' => '',
    ), $atts );

    return $a['product_id'];
}
add_shortcode( 'singleProduct_img', 'singleProduct_img' );

The shortcode I am using is: [singleProduct_img product_id="233"] and the output is "233"

Now i want that i can return the image of the product with id="233"

BTW:

Woo = version 2.6.8

WP = version 4.6.1–nl_NL

Any help wil be appreciated,

Thanks

Xxx red
  • 45
  • 1
  • 2
  • 11

1 Answers1

2

Use get_the_post_thumbnail():

return get_the_post_thumbnail( $a['product_id'], 'medium' );
Andy Tschiersch
  • 3,716
  • 1
  • 17
  • 24
  • damn... Didn't think the solution was that easy :( is there also such kind for the $ price of the product?? :o – Xxx red Nov 25 '16 at 14:06
  • 1
    Look here: [http://stackoverflow.com/questions/30165014/how-to-display-woocommerce-product-price-by-id-number-on-a-custom-page](http://stackoverflow.com/questions/30165014/how-to-display-woocommerce-product-price-by-id-number-on-a-custom-page) – Andy Tschiersch Nov 25 '16 at 14:08