• Resolved rodsn

    (@rodsn)


    Hello! I am trying to add items to the cart with the custom fields that have been selected in a custom form i made. So far i have been able to add the product to the cart and even change the price (although i think my approach is not the best, as I’m using woocommerce_before_calculate_totals), but i can’t seem to add the meta data to display the selected options bellow the item title.

    Is there a way to do this properly? This is urgent as the deadline nears and i have not yet been able to do this… Thank you in advance!

    • This topic was modified 1 year, 5 months ago by rodsn.
Viewing 4 replies - 1 through 4 (of 4 total)
  • Plugin Author Wombat Plugins

    (@maartenbelmans)

    Hi @rodsn,

    Our plugin is already a “form builder” so I’m not sure I understand the use case. 🙂 Can you explain why it needs to be a custom form rather than what WooCommerce supplies?

    Thread Starter rodsn

    (@rodsn)

    Hey Maarten!

    We have decided to use Elementor forms to handle the submissions, because we need all the fields it offers and because the clients are used to making forms with Elementor. I made a custom field type for the Elementor form that lists all of the products so the user can select the ones they want and then proceed to checkout.

    We run the code bellow for every selected product, and it successfully adds it to the cart. Now the only thing left to do is to change the meta data and price just like your plugin does when i buy it through the product page.

    $key = WC()->cart->add_to_cart($product_id, 1, 0);

    • This reply was modified 1 year, 5 months ago by rodsn.
    • This reply was modified 1 year, 5 months ago by rodsn.
    Plugin Author Wombat Plugins

    (@maartenbelmans)

    Hi @rodsn

    Thanks for explaining! This approach could lock your client in, as they’d need custom coding to map form inputs to price changes. If they want to update the form or add new fields, they’d have to modify the custom code.

    To do this securely, you’d need to hook into the entire add-to-cart process, from validation to checkout to order creation. Unfortunately, we can’t assist with this, as it’s outside the scope of our plugin.

    Good luck!

    Plugin Author Wombat Plugins

    (@maartenbelmans)

    To add to my previous comment: note that some standard WooCommerce features like “order again” will not work properly anymore if you custom-code this without taking all those features into account.

Viewing 4 replies - 1 through 4 (of 4 total)

The topic ‘Adding fields via code’ is closed to new replies.