如何在woocommerce产品详情页的描述里自动调用产品图,包括主图和缩略图

可以在functions里添加如下代码:

// Display description tab when empty
add_filter( 'woocommerce_product_tabs', 'display_description_product_tabs' );
    function display_description_product_tabs( $tabs ) {

    $tabs['description'] = array(
        'title'    => __( 'Description', 'woocommerce' ),
        'priority' => 10,
        'callback' => 'woocommerce_product_description_tab',
    );

    return $tabs;
}

// Add image to description
add_filter( 'the_content', 'add_product_image_woocommerce_description' );
function add_product_image_woocommerce_description( $content ) {
    global $product;

    // Single product pages (woocommerce)
    if ( is_product() ) {

        ob_start(); // Start buffering

        // HERE your main image
        echo $product->get_image( array('700', '600'), array( "class" => "img-responsive" ), '' );

        $image_content = "";

        // Loop through gallery Image Ids
        foreach( $product->get_gallery_image_ids() as $image_id ) {

            echo 'image_content';
        }

        echo '

TEST Image content

'; // Testing text // Inserting the buffered content after $content .= ob_get_clean(); } return $content; }

如果每张产品图要换行显示,则修改下面这行代码:

 echo 'image_content';

前后加上
:

 echo '
image_content
';

你可能感兴趣的:(woocommerce,产品描述里显示产品图)