Change main price when add to cart using opencart2.3 - php

I have OpenCart v2.3 and I need make customize on product details page.
Explain what I need:
The product take price from the admin panel by default.
I need add custom price when user click add to cart button.
Explain how OpenCart adds product to cart:
When user click on add to cart button, ajaxFunction is called and goes to checkout/cart/add function with all input fields.
Inside function add() in cart controller
$this->cart->add($this->request->post['product_id'], $quantity, $option, $recurring_id);
And system/library/cart/cart.php contains all functions
How can apply this idea?

"How can apply this idea?"
With difficulty, because it will affect a lot of parts of the system.
Perhaps you should consider having a second copy of the product with a different price and your code adjusts just the template so that clicking "Add to Cart" actually adds the second product instead.

Related

With Gravity Forms Product Add-ons + Woocommerce, is possible to create an add to cart link?

Here's the scenario:
I have a product using gravity forms product add-ons with prepopulated fields in the URL.
Example: website.com/product/book/?title=BookTitle&price=9.99
When a user clicks the link, the fields are prepopulated into the product so when the user clicks the add to cart button on the product page, the details are injected into the product and displayed on the cart & checkout pages. This part works well.
Is it possible to create an add-to-cart link that includes the URL parameters?
Example: website.com/cart/?add-to-cart=20762&title=BookTitle&price=9.99
I know this probably doesn't work like this, but ideally, I want a simple add to cart button that adds the product to the cart and also includes the URL parameter information.

How to add the buy now button to a product with hidden add to cart button?

I have items that are using Woocommerce Product Add-ons. This plugin uses the POST method, however I wanted to keep the Ajax buttons for the other products.
Based on "Remove add to cart button for specific product categories in WooCommerce 3" answer code That removes the add-to-cart button for specific product tags on single product pages, but problem now is I have no button to show.
The code replace also the ajax add to cart button by a button linked to the product and on single product pages, when hitting RETURN/ENTER key, the product is added to cart, which is exactly what I wanted. However, I want to have a Buy Now or Submit button in place. What should I do?

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.

WooCommerce: Add to Cart Button with Quantity - outside WooCommerce Loop

In addition to the WooCommerce product home page, I coded a second page template (with the wordpress page template function https://developer.wordpress.org/themes/template-files-section/page-templates/) that shows the woocommerce products in another schema.
... we call it „speed buy“, there is no informations about the products, just a list with title, price and the add to cart button.
My problem is, that we want to have not the normal add to cart button, but the add to cart button with quantity. Actually we call the add to cart button with
<?php do_action( 'woocommerce_after_shop_loop_item' ); ?>
But this is the normal one without quantity.. any ideas?
Edit: We display the products on the page-template with a custom loop / WP_Query.

Woocommerce separate orders when add to cart is clicked

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/

Categories