Forum Replies Created

Viewing 12 replies - 1 through 12 (of 12 total)
  • Thread Starter zlanich

    (@zlanich)

    Hey @claudiosanches, if you have a minute, I have everything working and still am unable to figure out how to accomplish the above most recent question, and I have one more question:

    Currently, I’m using a Coupon (as you know) to add the “Beans” to a cart, and I’ve properly disguised it so it doesn’t look like a Coupon, but I’d like “Other Coupons” to still be able to be used alongside the “Beans Coupon”, even if the other coupons are marked as “Not to be used with other coupons”. Do you know of an intuitive way for me to hook in and exclude my “Beans Coupon” from being considered for the “Not to be used with other coupons” feature for all other coupons in the cart?

    Thanks again. You’ve been very helpful and I’ve gained a much better understanding of the inner workings of WooCommerce and Composite Products that to that.

    Thread Starter zlanich

    (@zlanich)

    Ok, @claudiosanches I have the redemption process working via the woocommerce_update_cart_action_cart_updated hook and all is well except one thing so far:

    Currently, I’m using JS to refresh the entire page after I apply points via AJAX because I’m not certain how to tell WooCommerce to refresh its fragments after my AJAX call updates the cart with a different Beans Coupon Amount. Is this possible?

    Thread Starter zlanich

    (@zlanich)

    @claudiosanches, I’m not removing “all” coupons. I’m only removing my own, and here’s why:

    I want all “other” coupons to be able to apply to their fullest potential (for running sales, etc), then allow the user to apply points to the remaining balance. In testing, if I leave the Beans Coupon on, then apply another one that’s say 99% off, it results in you still spending your Beans, but the 99% off coupon doesn’t actually save you 99% of your order total. I’d like to be nice to my customers and reconcile the Beans Coupon amount when other coupons are attached so they aren’t spending more Beans than they have to.

    However, it was just a thought that I don’t think I need to hook into “before” the cart is modified to do this; I could just use the woocommerce_update_cart_action_cart_updated hook, remove the coupon, recalculate totals, then re-attached the Bean coupon, correct?

    Thread Starter zlanich

    (@zlanich)

    Ok @claudiosanches, I’d really like your advice on a specific thing moving forward before I dive into a major refactor. Here’s my “Points Cart Redemption” class as it was working before the AJAX came into play: https://pastebin.com/TB6xRKL6

    Prerequisite knowledge: “Beans” = Points (it’s a coffee-related site)

    Here’s the procedure I’m attempting:

    On “any” update of the cart that can affect the totals “After” all “other” coupons, discounts, etc, I’d like to do the following:
    – Before anything in the cart changes, temporarily remove the coupon I’m using to apply Beans to the order
    – Allow all other coupons, etc to be applied
    – Reconcile the remaining balance before taxes, etc and use that as my “Max Beans” number
    – Then re-apply the Beans Coupon, and if necessary, reduce it’s amount to the “Max Beans” (ie. in the case a user removes a cart item or reduces quantity)

    I see there are a ton of AJAX actions that could result in cart total changes, and I’m not a fan of the approach I ended up with in attempts to accomplish the above, and you’ll see this logic in that class above. Here’s what I’d like your advice on:

    What is the best way within that WC AJAX class to accomplish the above steps? How can I be sure where I hook into will cover all bases for when the cart totals change? I don’t want to make the code convoluted if there’s a simpler way to do this.

    Also, if you think I’m going about it wrong in general, I’m open to your thoughts.

    Please and thank you. You’ve been very helpful. I owe you a drink ??

    Thread Starter zlanich

    (@zlanich)

    Funnny story Claudio. I inherited this project and it seems the previous developers did not keep WooCommerce (or anything) up to date, so I programmed out a fully working for WC v2.4.6 (before the cart was AJAX powered). That’s why I was so confused. I now have to port my logic over to play nice with the AJAX. It seems like most of it still works, but if I port everything into the AJAX hooks, I should have something close. I will keep you posted as soon as I port that over and some of the above questions will still apply (ie. post-order situations, etc).

    Thanks.

    Thread Starter zlanich

    (@zlanich)

    7. It looks like the cart automatically clears its contents after a while of inactivity (at least on my installation). In the case that the cart changes (updated quantity, removed item, cart automatically clears), how many different places would I need to hook into to make sure I clear my “Applied Points” under those conditions. The issue I’m trying to avoid is applying say “$20 in points” to a cart via a coupon, then the user changes the cart total to say $10, at which point I would have to reset the applied points because they not longer make sense.

    Help is hugely appreciated. I’ve dug through code and docs and some of this stuff is hard to “be sure” about. Thanks!

    Thread Starter zlanich

    (@zlanich)

    5. If I am to support refunds for orders that were paid for entirely or partially in Points, where would I be able to trigger my code to refund the Points as well?

    6. If I’m using coupons to apply points to an order, would deleting the coupon after its initial use completely remove any trace of the portion of the order that was paid for in points? If so, I would have to probably set some post_meta on the order to store how many points were used in the case that a refund was needed.

    Thread Starter zlanich

    (@zlanich)

    I re-read and saw your comment about restricting by email, so disregard #4.

    Thread Starter zlanich

    (@zlanich)

    Ok thanks, I have a few more questions:

    1. Ok, so say I have the “Apply Points” box, and the user increments the points applied for the first time. I will have to create this temporary/unique coupon, then change it’s value (likely using AJAX) every time the user changes the applied points value (maybe, see below).

    Is the Cart AJAX powered in any way? Is there any way to update the cart values without refreshing the page? Is it even possible to access the cart instance like so via AJAX?: WC()->cart->add_discount( $coupon_code )

    Also note, my understanding was that I would create this coupon via AJAX on the fly, then continue updating it’s value if/when the customer changes their Applied Points selection. If you think there’s a better way, let me know (ie. Possibly only creating the coupon AFTER the customer has selected their points and clicked “Proceed to Checkout”. I do still have to update the cart values “visually” for the user though.)

    Worst case, I can forego the AJAX thing, and make the user manually submit the “Apply Points” button, which would create the coupon and refresh the page.

    2. If the user abandons their cart, it would be nice to ditch that temporary coupon. Do you have a suggested way of handling that?

    3. After the order is complete, say I want to delete that coupon (so we don’t fill up the database with one-time-use coupons). How would that affect the order data? Would the order simply have a different amount for “Total” & “Paid” and no mention of a coupon? I just want to make sure if there’s a source of confusion by deleting the coupon that I take care of it the best I can.

    4. Does the code above restrict the use of the coupon to only that customer in any way, or do I need to add additional logic to do so? If so, is there a way to do that? (Note: If I delete the coupon after the order, this isn’t really an issue, but I’m considering al my options.)

    Thread Starter zlanich

    (@zlanich)

    Hey @claudiosanches, thanks for the feedback. I’m stuck with myCred unfortunately because I’m tackling a rather tough task of intercepting social shares and turning them into points. There aren’t very many integrations out there for that that fall in line with our project specs, so I had to pick a combonation of a specific Sharing plugin + myCred.

    I’m fine with attempting to tackle this via a dynamic coupon though. My understanding of coupons is that they’re typically based on a percentage of cart total, or some other fixed rule. How might I go about creating a special coupon for this and making it dynamic?

    Bump.

    Does anyone know if W3TC is going to fix this? I had to manually remove that ‘&’ and use a backwards compatibility lib (https://github.com/SegFaulty/php-apcu-bc) to get W3TC to use APCu still. This is ridiculous. It’s been out for a while now.

    Thread Starter zlanich

    (@zlanich)

    I’m not implying we should clear the index if it fails due to server time out. I’m implying if mass changes were made to the posts or anything else that would affect Relevanssi results and we needed to re-index all of the content, there’s no way to clear the index and re-index everything without manually deleting the rows in the database. That’s where a “Clear Index” button would be convenient.

    P.S. You should consider implementing a simple Javascript queuing system that can kick off multiple indexing requests one after another rather than making user babysit the “Continue Indexing” button.

Viewing 12 replies - 1 through 12 (of 12 total)