【问题标题】:Wordpress / Woocommerce Get single product photo by IDWordpress / Woocommerce 通过ID获取单品照片
【发布时间】:2017-04-09 22:32:09
【问题描述】:

我正在尝试为 wordpress / WooCommerce 构建自定义简码,这样我就可以只选择一个产品的图片或价格,因为我想为产品页面设置样式,但我不能用自己制作的简码...

我在谷歌上看了很多,尝试了多个代码 en previewuws 但没有成功:(

也许有人可以帮助我?

这就是我现在所拥有的,到目前为止还有效!!

//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" 的产品图片

顺便说一句:

Woo = 2.6.8 版

WP = 版本 4.6.1–nl_NL

任何帮助将不胜感激,

谢谢

【问题讨论】:

    标签: php wordpress shortcode


    【解决方案1】:

    使用get_the_post_thumbnail():

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

    【讨论】:

    猜你喜欢
    • 2016-05-11
    • 2023-04-07
    • 1970-01-01
    • 2016-09-13
    • 1970-01-01
    • 2016-09-27
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多