2016-11-25 142 views
0

我正在尝试为wordpress/WooCommerce构建自定义简码,以便我可以选择图片或仅仅是单个产品的价格,因为我想要设置产品页面的样式,但我不能这样做与通过自理作出的简...Wordpress/Woocommerce通过ID获取单张产品照片

我已经看过很多关于谷歌,tryed多码EN previeuws但没有更迭:(

也许有人谁可以帮我吗? ?

这就是我现在和这个作品迄今!!

//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'); 

我使用的简码为:[singleProduct_img product_id="233"],输出为“233”

现在我想,我可以使用id =“233”

BTW退回产品的形象:

呜=版本2.6.8

WP =版本4.6.1-nl_NL

任何帮助时便会理解,

感谢

回答

1

使用get_the_post_thumbnail()

return get_the_post_thumbnail($a['product_id'], 'medium'); 
+0

该死的......没想到的解决方案是容易:(有也是这类的产品的价格$? :o –

+1

看这里:[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) –