dsf1222
2018-10-11 11:53
浏览 26
已采纳

在Woocommerce 3中访问Shipping Rate对象数据

I want to get the possible shipping methods in Woocommerce. I can get to the Class WC_Shipping_Rate class but i don't know how to get 'deeper' and it's driving me crazy.

Here's my code:

$packages = WC()->shipping->get_packages();

foreach ( $packages as $i => $package ) {

    foreach($package['rates'] as $value){
        echo '<pre>'.var_export($value, true).'</pre>';
    }

}

This piece of code prints this on my screen:

WC_Shipping_Rate::__set_state(array(
   'data' => 
  array (
    'id' => 'flat_rate:1',
    'method_id' => 'flat_rate',
    'instance_id' => 1,
    'label' => 'Per post',
    'cost' => '2.50',
    'taxes' => 
    array (
    ),
  ),
   'meta_data' => 
  array (
    'Items' => '1 Kip × 1',
  ),
))
WC_Shipping_Rate::__set_state(array(
   'data' => 
  array (
    'id' => 'free_shipping:2',
    'method_id' => 'free_shipping',
    'instance_id' => 2,
    'label' => 'Download kaart',
    'cost' => '0.00',
    'taxes' => 
    array (
    ),
  ),
   'meta_data' => 
  array (
    'Items' => '1 Kip × 1',
  ),
))

My question is: How can i access the data array and then the label value? I know how to get the label value, but i cant 'reach' the data...

I have tried to get it using methods, more arrays but the WC_Shipping_Rate::__set_state(array( is confusing me. Any help would be appriciated.

  • 写回答
  • 好问题 提建议
  • 追加酬金
  • 关注问题
  • 邀请回答

1条回答 默认 最新

相关推荐 更多相似问题