Ubercart add to cart trigger? - drupal

I want to keep track of all items added to uber cart. I.e. Whenever someone clicks ADD TO CART, I want to: create a database entry of the time and item added.
This way I can see which items are most clicked on.
The logic to add it to a db etc is easy to do. What I need to know is, how do I plug into the "add to cart" part. I.e. How do I know when this has been clicked?

You should be able to implement hook_add_to_cart in a custom module, which will get called exactly as you describe above.

In Drupal 7 it changed to hook_uc_add_to_cart

Related

WooCommerce Variation Try or Buy with ACF

I have a strange request that I don't know how to approach or get working with WooCommerce.
On the product page we have two options. Buy or Try this product.
So generally "Buy" for say, $49.95 would include shipping and you can checkout as normal.
But "Try" for say $6.95 - that $6.95 is your shipping charge to try it, and the full product price at the end of the 15-30 days is the $49.95.
When you select Try you need to agree to some terms and conditions before you can add it to the cart.
So I think Advanced Custom Fields to add a conditional WYSIWYG to add in some specific information and make the Checkbox required to add to cart. I'm not required to think about the billing side of things just to get this Try or Buy working on a product page.
How the heck do I do this?
This is pretty straight forward with ACF.
Create a field like you mentioned as a wysiwig editor for the content.
Create a checkbox field and set Required: to yes. Add conditioning to hide it unless the checkbox from clicking the trial button is populated.
Create a checkbox field, that you will use to create the Trial button. Restyle it to be a button.
Now on the try button, add some JS in order to make a popup appear.
They read the popup and check the box.
Do an if statement to check if the checkbox has accept or whatever you set the checked yes value to. If it is equal to that value, add a styling or class to the try button to make it disappear. Remove styling or a class off an extra button that allows you to then get the product buy pressing it.
This seems like it would work, you'd then just need to figure out how to get the product charge to differ. Perhaps when they click that button it populates a hidden coupon field which applies a discount to the basket making it the amount you want the cost to be? Or it changes the value they have to pay. I will let you figure that one out.

Unique issue with WooCommerce and hiding the add to cart button..?

We have a plugin that allows people to submit offers on products, and then the site owner can accept, counter, or decline offers, and you can negotiate back and forth until a price agreement is reached.
We are using the woocommerce_after_add_to_cart_button hook to add the offer button after the cart button.
We are getting lots of feedback that people want to leave the price of the product empty so that it simply display a price on the site, it won't display the Add to Cart button, but they do want it to display the offer button and allow that functionality.
If you set the price to 0.00, then it says FREE on the site, and still includes the add to cart button, so that's no good.
When left blank, though, the problem we run into is that when a customer clicks to buy a product from an accepted offer, WooCommerce keeps removing the item out of the cart because it says it's not purchase. This is happening because of the is_purchasable() function. With a blank price WC says the product is not purchasable, so it will automatically remove itself out of the cart, which it is indeed doing.
There is a hook available that allows us to force $purchasable = true for the product, but then of course that makes the Add to Cart button show up again, which doesn't make sense for this use-case.
So as it stands now we're at that point. We've got the system overriding $purchasable so that we can complete the checkout on a product with an empty price, but it's leaving the Add to Cart button, which allows the person to add the product at 0.00.
I'm stumped on the best way to hide to the Add to Cart button in this scenario..?? I would usually hide it by using that hook to make $purchasable = false, which takes care of it nicely, but in this case I can't do that because that's what keeps us from being able to purchase the product, of course.
Any information on a way around this would be greatly appreciated!
UPDATE
I found this tutorial for overriding core template files from a plugin: https://www.skyverge.com/blog/override-woocommerce-template-file-within-a-plugin/
So I think what we're going to try is to basically say "if $purchasable = false and $offers_enabled = true, then use these templates for the add to cart button."
Within our template we're doing nothing but commenting out the actual <button> element. This leaves all hooks in place, but hides our button.
Decent solution? Horrible idea?

How to force addition of Product B in order to add product A in Drupal 7?

I am looking for an easy way to associate two products with each other on checkout while at the same time forcing the user to create the association if it doesn't exist yet. Basically, a user can by hosting, but in order to complete the checkout, they also need a domain name. I have classes for each, but I am trying to think of ways to solve two problems:
On checkout, display that two products are associated
Force the user to create the association
Any ideas on what I can use to do that?
UPDATE
What I did was:
Created two separate products
If you add the one, it does a check to see if this item has been linked to another product
If not, it takes you to a custom page forcing you to add and assign the other product
This works, but it's not very elegant. Any better suggestions would be much appreciated.
Use Rules to display messages to the user. Use the event on "add to cart", check the type of product, then check to see if the associated product is added to the cart, if not show message saying you also need to add a hosting package and auto redirect them there. Then upon checkout, check to see if one of those products exist, does the other exist in the cart? Throw same message and auto redirect them to the missing one.
You may need to use components with your rules to get the full effect. But that is what I would do.

Wordpress Advanced Custom Fields - Limit A User's Choice To One Option

I have a WordPress website and as part of the news items, the editor can add either an:
internal link OR
external link OR
file
Currently I have this set up as a repeater field with maximum rows set to 1.
Is it possible if say one value has been entered, to prevent another of the values from being filled in.
E.g. I add an internal link and then try to add an external link. A message of some sort is then shown to me to say that only one value can be selected at a time.
I know I can add a description to the field with this information but I want to make it idiot proof so that the user can never add more than one value.
Thanks for your time and help in advance.
I can't write this in comments but celeriko right. Install types plugin there is ability of conditional logic. You can very easy implement of from backend.
Types: http://wp-types.com/
Reagrds

Where to find the data from add to cart button when clicked using MarketPress in Wordpress?

I was wondering if someone could guide me through the MarketPress plugin for Wordpress. I'm about to determine whether the item or the products is still available or out of stock. I don't know where to find the table where the data is being inserted. In the first place, I don't know where to locate the specific method or function that inserts the purchase details when I click the add to cart button. Please help. :(

Resources