WooCommerce, manually add a product and price for purchase - php

I'm trying to figure out if there's a way to use the WooCommerce Cart and Checkout functionality if I need to purchase something that isn't technically a product
In other words, it's a completely independent "membership" that needs to be purchased, but isn't a product post.
I'd love to be able to add an item in the cart manually ... manual name, manual price, manual meta data and then purchase.
Does anyone have any idea how to do this?

here is example
global $woocommerce;
$woocommerce->cart->add_to_cart(16);
16 -> this is ID of existing product in store
documentation Link

Related

WooCommerce Meta-key for products in cart

First post here so I'll try to make it as good as possible.
For a WooCommerce / WordPress project, I'm trying to achieve the following. When the cart is empty, there should be a button displayed with the text "Return to store".
Now the button isn't the problem, I've added this with Elementor, now usually I use the JetEngine Dynamic Visibility option to show/hide things.
I've also done this with stock status. There I used the _stock option to only display when there are 5 or more in stock left.
So I'm trying something similar with the cart, whenever there are 1 or more items in the cart, this button needs to be hidden because whenever someone has 1 item in their cart we want them to proceed to the checkout and not return to the shop, because the average product bought per order is 1 for this particular shop.
But the one thing I can figure out is, what key do I need to use to check items in the cart?
I've been trying several options I found online but none seem to work.
Does anyone know how to do this?
Thanks!

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.

Add custom product to cart in WooCommerce

I am currently developing an interface that allows you to customize a product. I am implementing on Wordpress, but I need to generate an order after you finish the customization process. So it is necessary that the data is added as a product in the shopping cart WooCommerce. Is that possible? What would be the procedure?
As per your requirements i assume a following scenario
For example you have a site which which sells printed Tshirts.
The flow of this example site is that a user comes selects a tshirt, customizes the tshirt product say by adding Tshirt's color, Image on tshirt and Tshirt's size.
These customization added by the customer at the frontend on product page or cart can be stored in post meta for that order.
So if your case is some what like this then Yes this is possible.
And you can use the following links which will help you to achieve your goal.
How to Add Custom Data to WooCommerce Order
and
Custom WooCommerce Order Meta
Let me know if this solution works for you.

magento add extra product to cart automatically

I want to add products automatically to my magento cart.
The situation is I have product Y and it needs extra components to be assembled, so I want that the assembly parts to be added automatically to the cart when product Y is added.
I have googled a lot and could only find extensions for promotion product and free gifts but I need a solution which just adds the product to the cart and that it adds in the same quantity of product Y.
Are there extensions which I can use or how can I alter my code to get my desired behaviour?
You can use that kind of extension or make you own with a listener on the sales_quote_item_set_product event to check if the product added is yours and need a new product to be added.
I had a similar request that was abandonned as it is illegal in France (and in most of the part of Europe) to sell a product linked to another and that was not requested. Moreover, the customer can already have this second product and do not want it. We added a popup that said which products can be needed with this one. This second part is just an advice.
Well, if you looking programming solutions:
Write Custom module that observe event checkout_cart_add_product_complete.
In your observer, add products by following code.
The code is:
$prouctToAdd = Mage::getModel('catalog/product')->load('product_id ');
$qty = 'currently_added_produt'
$cart =Mage::getSingleton('checkout/cart');
$cart->addProduct($product, array('qty'=>$qty));
$cart->save();

Magento require coupon to purchase product

After searching on Google for quite a while I am going crazy.
My question: Can you configure Magento to require a coupon code to buy specific product?
This is for a promotion my employer is running, basically we want to allow specific customers to buy specific product in our Magento store before any of our other customers. Thank you for your suggestions.
A brief idea I can give here.
Create a backend module, which has own db tables to save linking of products ID to specific coupon, multiple coupon or just a check that coupon is required, depending on your case. From this Module you should be able to define such linking of product to coupon.
Since customer apply a coupon code at cart page, so we will let customer add product into cart. Then edit isDisabled method of Mage_Checkout_Block_Onepage_Link class. where you will check if your quote has any product from the product-coupon linking defined in your module and coupon is not applied yet. Similar thing you can should do for Multishipping method if it is enabled in your Magento. So whenever coupon coupon code will be applied page will refresh and button will get enabled.
Same check you will need to put in indexAction of Mage_Checkout_OnepageController.

Categories