I have installed woocommerce to handle product input & checkout process of a wordpress shop.
The shop page is custom built which allows the user to pick a product from a list and customise it which outputs a price in javascript based on information stored in the database.
The products stored in the db are valued at 0.00 because they're different prices depending on the variables chosen.
The output data I'm ready to pass to woocommerce is as follows:
- WC Product ID (This matches a product in the db)
- Custom Price
- Custom Image
- Custom Description (e.g. 100mm x 100mm)
- Build Data (to be stored against the item but not seen in checkout)
I'm trying to find a way to add a product to the cart using the product ID (to make it valid) and then overriding the price with the custom price and attaching meta data which most will be seen at checkout and one will be hidden until seen in the wordpress admin.
Adding the product to the cart is achieved by using:
$woocommerce->cart->add_to_cart($_POST['custom_product_id']);
After which point I'm finding it impossible to override the price and add additional information.
Step 1:- You need to create some custom hidden fields to send custom data that will show on single product page. for example :-
Step 2:- Now after done that you need to write the main logic for Save all Products custom fields to your cart item data, follow the below codes.
Step 3: you need to override the item price with your custom calculation. It will work with your every scenario of your single product sessions.
Everything will be done inside the functions.php
Reference Site
All of this code goes into functions.php
This captures additional posted information (all sent in one array)
This captures the information from the previous function and attaches it to the item.
This displays extra information on basket & checkout from within the added info that was attached to the item.
This adds the information as meta data so that it can be seen as part of the order (to hide any meta data from the customer just start it with an underscore)
If you want to override the price you can use information saved against the product to do so
All your custom information will appear in the customer email and order from within wordpress providing you added it as meta data (4.)