2

I am using CoCart plugin with WooCommerce. I have a cart with products and the plugin counts me the totals and actually everything. I would like to apply coupons, I made a plugin for this, but I had no idea how to get the cart which had been initialized with CoCart. I tried this: WC()->session->get( 'cart_totals' ) and this: WC()->cart, but in both cases the session and cart is null. So I need a solution to make it possible to get the previously created cart.

flomei
  • 860
  • 1
  • 11
  • 36
gmark11
  • 65
  • 1
  • 10
  • Which version of CoCart are you using? Lite or Pro? Only CoCartPro has the functionality to support Coupons. See [features](https://cocart.xyz/features/) page and [documentation](https://docs.cocart.xyz/pro.html#coupons-applied-coupons) for pro. If you have the lite version, you might have to go through their documentation to figure out if there is indeed a place for you to extend this functionality. – shivaramanaiyer Aug 31 '20 at 05:16
  • I am using the Lite version. And this is what I want to make it possible to apply coupons with this version too. – gmark11 Aug 31 '20 at 07:32
  • Well, in that case, you will have to look at the CoCart Lite's code to see if there is even a possibility to achieve such a thing. Although I highly doubt that they would have such a functionality in place. – shivaramanaiyer Sep 02 '20 at 14:31
  • Why did you decide to not award the bounty when you chose to accept the Answer? – Scratte Sep 08 '20 at 19:43

1 Answers1

1

a mildly different Solution is discussed in this thread, have a look. below is the excerpt copied from there. the question was initially asked by msargenttrue and answered by Freney

the post suggests that you need to do a manual implementation in PHP which is just copypaste , and call the script to apply on the intended product in database. THREAD <-- the PHP implementation part

FOR the problem

So I need a solution to make it possible to get the previously created cart.

you must try the js implementation of local storage, the stored item remains on the user device until the cart is cleared explicitly.

localStorage.setItem("cart", "CartID-002");
localStorage.clear() #when you want to remove.

Points to remember The main features of localStorage are:

  1. Shared between all tabs and windows from the same origin.
  2. The data does not expire. It remains after the browser restart and even OS reboot.
nikhil swami
  • 2,360
  • 5
  • 15