2017-08-15 5 views
0

私のWordpressウェブサイトでは、CheckoutページのWooCommerceを使用して、写真がCheckoutの商品リストの上に表示されています。表示されているように、どのように製品のリストに表示させるのですか?商品写真はCheckout(Wordpress/WooCommerce)の商品リストの上に表示されます

enter image description here

これは私が現時点で持っているものです。

add_action('woocommerce_checkout_before_order_review', 'displays_cart_products_feature_image'); 
function displays_cart_products_feature_image() { 
    foreach (WC()->cart->get_cart() as $cart_item) { 
     $item = $cart_item['data']; 
     if(!empty($item)){ 
      $product = new WC_product($item->id); 
      // $image = wp_get_attachment_image_src(get_post_thumbnail_id($product->ID), 'single-post-thumbnail'); 
      echo $product->get_image(); 

      // to display only the first product image uncomment the line bellow 
      // break; 
     } 
    } 
} 

これはGet Cart products id on checkout WooCommerce page, to display product imagesに関連しています。

ありがとうございます!

enter image description here

+0

...どのようにあなたがそれをコーディングしていますか? – Reigel

+0

申し訳ありませんが、追加してください。それは今、元の投稿にあります。 –

+0

あなたのフックは 'woocommerce_checkout_before_order_review'ですので、テーブルは注文レビューです – Reigel

答えて

1

代わりのwoocommerce_checkout_before_order_review、我々はこのようなwoocommerce_cart_item_nameフィルタ使用することができます。これは何をするか

add_action('woocommerce_cart_item_name', 'displays_cart_products_feature_image', 10, 2); 
function displays_cart_products_feature_image($cart_item_name, $cart_item) { 

    return (is_checkout()) ? $cart_item['data']->get_image() . $cart_item_name : $cart_item_name; 

} 

を製品名の前に画像を入れています。それでも

reigelgallarde.me

ない、我々は右の必要なもの:以下、この画像のような何か?はい、それは私たちが得ることができる最も近いものです。そして、ちょうどいくつかのCSSがこの問題を解決します。

.woocommerce-checkout-review-order-table .cart_item .product-name img { 
    float: right; 
} 

は、以下のようになります。 依存enter image description here

+0

それはうまくいった! xxx –

+0

素晴らしい!答えを受け入れることを忘れないでください。 :) – Reigel

+0

それはちょっとした仕事ですが、私の元の投稿の最後のスクリーンショットを見ることはできますか? custom.cssのCSSコードを使用しているにもかかわらず、右側に表示されないようです。 –

関連する問題