8

我正在构建一个自定义运输方式插件,我需要为其访问运输方式变量。

      echo  "<pre>";
        print_r( $woocommerce->shipping->get_shipping_methods);

      echo"</pre>";

在我的插件中这样做会返回一个空集或数组,而,

echo  "<pre>";
    print_r( $woocommerce->shipping->get_shipping_methods);

  echo"</pre>";

返回预期值(可用的运输方式)任何想法是由于某种错误还是什么?

这是正在运输的物品 -->

WC_Shipping Object
(
    [enabled] => 1
    [shipping_methods] => Array
        (
        )

    [shipping_total] => 0
    [shipping_taxes] => Array
        (
        )

    [shipping_label] => 
    [shipping_classes] => Array
        (
        )

    [packages] => Array
        (
        )

)
4

2 回答 2

6

我正在使用以下代码段:
$shipping_methods = $woocommerce->shipping->load_shipping_methods();

这将为我返回运输方式。

于 2013-05-10T08:34:34.847 回答
2

我看不出您发布的两个代码块之间有任何区别,但我认为这样做的正确方法应该是进行函数调用,而不是将其作为类的属性进行访问。

echo  "<pre>";

print_r( $woocommerce->shipping->get_shipping_methods() );

echo "</pre>";

(注意 get_shipping_methods 后面的括号)

于 2013-05-09T12:08:25.080 回答