• I have a very weird problem here. I want to use the first product attachment gallery image as product thumbnail in cart page.
    So I use below code in cart.php to get gallery attachment id:

    $attachment_ids = $_product->get_gallery_attachment_ids();

    The weird thing is, it worked perfectly on my localhost (my test website, which woocommerce version is 2.6.8). But it couldn’t get any data of the variable products on my online website (which woocommerce version is 3.1.2). However, it could get the correct data of simple products.

    The localhost website and the online website all use the same theme, I don’t know why they have different situation. I wonder is it woocommerce upgrade bug? Please help me, thanks.

    p.s. I use the same method to get related product’s attachment gallery images, and it all works.

    • This topic was modified 7 years, 6 months ago by ive6830.
Viewing 1 replies (of 1 total)
  • Thread Starter ive6830

    (@ive6830)

    I use print_r($_product) to see the data in it, and find out that
    WC_Product_Simple Object has correct gallery image ids, as below: [gallery_image_ids] => Array ( [0] => 1174 [1] => 1175 [2] => 1176 )
    But WC_Product_Variation Object has no value in the array: [gallery_image_ids] => Array ( )

    I think it’s caused by Woocommerce upgrade. Because my localhost has totally different object structure of $_product.

    Does anyone know another way to get gallery image ids of variable product in cart page please?

Viewing 1 replies (of 1 total)
  • The topic ‘get_gallery_attachment_ids() wrong value of variable products in cart page’ is closed to new replies.