0

我正在尝试获取在精美产品设计器中添加的元素的图像(或图像 URL)。我找到了以下代码,但这个代码是为当前颜色而不是当前图像编写的。显示了元素的标题,但我找不到找到图像(或图像 URL)的解决方案。

提前致谢!

add_filter( 'woocommerce_get_item_data', 'wc_checkout_description_tp', 10, 2     );
 function wc_checkout_description_tp( $other_data, $cart_item ){
 //re-convert the fpd dtails from the json sting to an array
 $fpd_detail_arr = json_decode( html_entity_decode( stripslashes(   $cart_item['fpd_data']['fpd_product'] ) ), true );
 //remove the first element as we are not dealing with shadows
 $fpd_elems_arr = array_slice($fpd_detail_arr[0]['elements'], 1);

 //loop each element and set the details to a var
 foreach($fpd_elems_arr as $elem_key => $element_arr){
     foreach($element_arr as $key => $value){
         //the currentColor value is set inside yet another array
         if(is_array($value)){
             foreach($value as $val_key => $val_val){
                 if( $val_key == 'currentColor' && !empty($val_val) ){
                     $fpd_detail_value = $val_val;
                 }
             }

         }
         //set the title value
         else{
             if( $key == 'title' && !empty($value) ){
                 $fpd_detail_name = trim($value);
             }
         }
     }
    //add the name and value pair to the detail array
     $other_data[] = array(
         'name' => $fpd_detail_name,
         'value' => $fpd_detail_value
     );

 }
 //return the final detail array
 return $other_data;
}
4

0 回答 0