Hope I understood your request correctly.
You say that you want to receive the details of the change (if any) of the product that is in the basket.
The cart contains many items. You can iterate over the elements and get information about each element.
The cart item is an associative array, and you can find the product identifier in $item['product_id'] and the change identifier in $item['variation_id']
Please use the following function and pass the variation identifier to get the details of the change:
function get_variation_data_from_variation_id( $item_id ) { $_product = new WC_Product_Variation( $item_id ); $variation_data = $_product->get_variation_attributes(); $variation_detail = woocommerce_get_formatted_variation( $variation_data, true ); // this will give all variation detail in one line // $variation_detail = woocommerce_get_formatted_variation( $variation_data, false); // this will give all variation detail one by one return $variation_detail; // $variation_detail will return string containing variation detail which can be used to print on website // return $variation_data; // $variation_data will return only the data which can be used to store variation data }
Now let's see how to use this function
$item_id = ( !empty( $cart_item['variation_id'] ) ) ? $cart_item['variation_id'] : ''; if ( !empty( $item_id ) ) { $variations = get_variation_data_from_variation_id( $item_id ); }
Hope this will be helpful.
Ratnakar - StoreApps
source share