Woocommerce separate orders when add to cart is clicked - php

I put a few custom fields as part of the add to cart form and I'm trying to separate the orders every time the add to cart button is clicked.
Right now when I order an item and fill up the form I get 1 item added to cart and if I fill up the form again with different data and click add to cart the new data gets lost and the count of the first product is increased to 2.
At the same time when viewing the cart page I want to be able to increase the count of separate orders when changing the count and clicking update chart.
What hook can I use to accomplish this? Thanks.

Don't add fields directly to add to cart form.
From admin panel make your product variant product. There you can add product variants like color, size etc. You can add your own variations also. This will automatically create extra fields to add to cart field.
Then, your products will be added separately.
Check out the link:
https://docs.woothemes.com/document/variable-product/

Related

Woocommerce -- Adding Products with Javascript/PHP

I have a custom form that users make various selections before being presented with products they can buy. I need to add some logic that if an input has been selected when the user adds a product to the cart, it will also add an additional product to the cart.
The input is 3 radio check boxes. Somehow I need to hook into the add to cart click and check the page to see if one of the radios has been selected and then add the appropriate product but I'm not sure where to start.
I know I'll need to have an action that runs something like:
WC()->cart->add_to_cart( 'product_id', 'quantity');
But I'm not sure how to hook into the initial add to cart click and how to check for the radios on the page.
Thank you for your help.
Not a lot of information to go off of here, but here is a few useful WooCommerce hooks to give you a starting point/ order of operations. When overriding any native action in WordPress or its plugins. You should use the hooks if available.
Add the radio inputs to the single product before the add to cart is added (hook):
add_action("woocommerce_before_add_to_cart_button", "your_input_render_function_here");
Add the new input data from the radio buttons to the cart item (filter):
add_filter("woocommerce_add_cart_item_data", "your_filter_function_to_capture_data_here");
Capture the data and render in cart (filter):
add_filter("woocommerce_get_item_data", "your_cart_render_function");
Finally, save the newly aquired data to the order (hook):
add_action("woocommerce_checkout_create_order_line_item", "your_function_to_add_to_order")
This is one of many directions you can take, depending on your requirements. I recommend giving it a shot, and if you still have issues return with an example of your code.

Add product to customer's cart from WP admin in WooCommerce

What I would need is possibility to prepare shopping cart content for selected user/customer in WP admin backend.
When they enter their cart page, they should see items/products I added along with items they added to cart, all together.
What would be the most proper way to achieve this? Thanks.
It's Fully customization as you want.
You can create a simple page in admin where you can select a user from drop down or you can select multi select drop down of user.
along with that you can get your product list that you want to add.
with all this thing you need to create custom table in database where this all data should store and we can get where we want.
select the user and select the product you want and save it so it will store data in you custom table with flag like pending or anything that can identifies that is not added in users cart yet.
now when user comes in and it's logged in then you need to check for database table, if there is a column of this user with pending flag then you need to add admin added items in users cart and for that you can find so many code.
after adding your product in cart you can change the flag or remain as it is.
you can try this way.

Change product price when option selected in Prestashop

I'm developing a module that appears in the product page. This module consist of a checkbox which when is checked, shows a few inputs to be filled by the client and add an extra amount of, for example, 50.
How can I add this amount to the product cart? I'm using the hook hookActionCartSave to retrieve the cart but I can't update it adding the amount of 50.
The ideal is to reflex this concept like shipping costs but I'm stuck on how to change the product price or add a new concept when the checkbox is checked and client click "Add to cart" button.
Thank you!

Add Custom Input Field on Woocommerce Cart Page

I've been developing a WooCommerce site and I have a task where I have stuck. I need to add an extra custom input field into the cart items table.
Like for example, if a person orders '2000 youtube views' package, then right below the item name, I want the user to input his Youtube video URL.
I know I can add custom input fields on Product Page and can simply make them display on the Cart Page. But I want to take user input data onto the Cart Page. Each cart item will have a custom input field. So far, I have researched a lot but didn't have any success for my solution. All I found that to print the custom input field data onto the cart page added on the Product Page.
Any help would be appreciated
I've had this problem also. I've solved it with this. Adding the fields on the cart page like you did but with jQuery receive those values and dynamicly transfer them with a GET request, ( adding them to the submit button ) and $_GET fill them in the checkout page in a hidden input type.

Edit Product Meta Data after adding to cart, Woocommerce

I'm new to wordpress and woocommerce, I need to edit few Product Meta Data of a product after it has been added to cart. I've used "WooCommerce Product Gift Wrap". I need to add a option to allow users to remove gift wrap (If they had selected from product page) and update the product pricing as well.
I tried to change value with $values['gift_wrap'] = "0";, but when I print the meta array again, I cannot change the actual data which woocommerce takes from session (or something else). Kindly check the attached image link for better understanding.
Thank you.

Categories