I have a custom plugin to generate pdf of my products. I am calling this function inside the plugin to get all the gallery images of a product.
function get_gallery_images(){
$product_id = 34560;
$product_obj = new WC_product($product_id);
$attachment_ids = $product_obj->get_gallery_image_ids();
}
This function works perfectly when the id of the product is fixed, but whenever I try to get the ID dynamically is stops working. My dynamic function is:
function get_images(){
global $product;
$attachment_ids = $product->get_gallery_image_ids();
}
It should work because I have seen people using this function but it doesn’t work for me and I am unable to identify the issue.