Woocommerce is returning empty array list while fetching shipping methods

别来无恙 提交于 2021-02-04 17:41:24

问题


I am building a custom shipping method plugin for which i need to access shipping method variables .

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

      echo"</pre>";

doing this in my plugin is returning an empty set or array while,

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

  echo"</pre>";

returns expected value(available shipping methods) any ideas is it due to some kind of error or what ?

here is shipping object which am getting -->

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

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

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

    [packages] => Array
        (
        )

)

回答1:


I am using the following snippet:
$shipping_methods = $woocommerce->shipping->load_shipping_methods();

This returns the shipping methods for me.




回答2:


try before call

$woocommerce->shipping->load_shipping_methods();



回答3:


I don't see any difference between the two blocks of code that you posted but I think the correct way of doing this should be to make a function call rather than accessing it as a property of the class.

echo  "<pre>";

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

echo "</pre>";

(Note the brackets just after get_shipping_methods)



来源:https://stackoverflow.com/questions/16460580/woocommerce-is-returning-empty-array-list-while-fetching-shipping-methods

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!