Support » Plugin: WooCommerce » how to list shipping options and costs without modifying the cart

  • I want to list the shipping options and costs for a product without adding it to the cart (like if the product were alone on the cart), also I don’t want the cart to be modified.

    What I tried so far is:
    To use new WC_Shipping and new WC_Cart, I’ve been reading api docs for like 1 hour and got nothing.

    To use global $woocommerce->shipping and $woocommerce->cart, I managed to empty the cart, add my product and get what I wanted, but I can’t restore the cart, after a while of trying stuff from api docs I’m out of ideas with this one.

    Any insight would be much appreciated, thank you.

Viewing 1 replies (of 1 total)
  • I improved and retested my second method, it is really ugly but it does the job.

    save the cart array, empty the cart, add my item, save my info, empty the cart, cycle thru the saved array to add the items back to the cart. I think the order of the parameters is different (array vs add function) and I didn’t notice the first time I tried this method, that’s why it failed for me.

    Now my ajax call to the function that does this is working perfectly but the same function called on a product page only returns 1 shipping method.

    I guess this is the wordpress style, take hours to solve 1 tiny problem, then wordpress will repay you with a quirk/bug that you have to track over 50% or more of your plugin files.

Viewing 1 replies (of 1 total)
  • The topic ‘how to list shipping options and costs without modifying the cart’ is closed to new replies.