问题
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