0

I am actually creating an order form (sort of). Based on the items a customer selects, logic needs to be applied to calculate the custom price per item. Custom price is now stored in hidden input fields.

What is the best practice to implement this? Eventually i would like to add all items and their custom prices added to the cart.

I am currently testing with a php function in combination with action woocommerce_before_calculate_totals.

global $woocommerce; $woocommerce->cart->add_to_cart(64,1,154, array(),array('add_length' => array('Option'=>'test'),'custom_price' =>1200.50));

As a standalone function it works. But integrating it to the page, i am not sure.

My questions;

  • How can i call this function from a button onclick event? The php function is stored in the function.php file
  • The custom price is calculated using a php function and stored in a hidden input field. Don't think this is the most secure way to do it. What is a better solution?
  • Preferable i have a function that i can use to enter product_id, qty and custom price. Add it to the onclick button. Everything in a secure way.

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Browse other questions tagged or ask your own question.