【问题标题】:Showing the main product image in the cart thumbnail, instead of the variation image in WooCommerce在购物车缩略图中显示主要产品图像,而不是 WooCommerce 中的变体图像
【发布时间】:2017-03-22 02:48:43
【问题描述】:

我有一家 WooCommerce 商店,里面有多种产品。

在购物车中,它显示产品变体图像的缩略图。这不好,因为变体实际上只是一个文本图像,所以你看不到文本的实际产品。

如何强制 Woo Commerce 仅显示主要产品图片,而不是购物车页面上的变体?

谢谢!!

【问题讨论】:

标签: php wordpress woocommerce


【解决方案1】:

在活动主题的functions.php 中添加以下代码。

function getCartItemThumbnail( $img, $cart_item ) {

    if ( isset( $cart_item['product_id'] ) ) {
        $product = wc_get_product($cart_item['product_id']);

        if ( $product && $product->is_type( 'variable' ) ) {
            // Return variable product thumbnail instead variation.
            return $product->get_image();
        }
    }

    return $img;
}

add_filter( 'woocommerce_cart_item_thumbnail', 'getCartItemThumbnail', 111, 2 );

【讨论】:

  • 请耐心等待,因为我是新手。这会添加到 cart.php 中吗?这是调用缩略图的部分: get_image(), $cart_item, $cart_item_key ); if ( ! $product_permalink ) { echo $thumbnail; } else { printf( '%s', esc_url( $product_permalink ), $thumbnail ); } ?>
  • 或者我可能会添加到functions.php?
  • 我添加到函数文件中,它仍然返回变体图像。
  • @MelissaBanks - 您可以将代码添加到单独的或现有的插件文件或主题的 functions.php 中。另外,正如我提到的,您需要添加代码来获取主要产品图像。
  • 啊,好吧-抱歉,就像我在这里说的有点新手,还在学习。
猜你喜欢
相关资源
最近更新 更多
热门标签