WooCommerce Shipping API functions

2019-09-03 08:39发布

问题:

I have WooCommerce Conditional shipping & Payment, Table rate plugin installed. I am trying to create an API functions for mobile to get shipping methods from WordPress WooCommerce.

i have the 2 plugin install with the settings below Woocommerce conditional shipping & payment

and table rate shipping

let say i can get the basic default woocommerce shippings and calculation correct. but how can i get the condition restrictions from the 2 plugin? i have no idea which methods in these 2 plugin to use to get the conditions.

If Anyone have done this before or have some clues please helps Thanks.

回答1:

Simply this 3 line of code it will get available shipping methods for you from cart items

    global $woocommerce;
    $cart = wc()->cart->get_shipping_packages();
    $shippingMethods =  wc()->shipping->calculate_shipping_for_package($cart);
    return $sm;