I'm working on a payment gateway plugin for WooCommerce and I need to edit the checkout form. When the user has selected 'Sweden' as their country, and they selected 'Klarna' as their payment method, an extra input field should appear for the user's social security number (this is totally normal in Sweden, really).
As far as I understand, the woocommerce_checkout_update_order_review action gets triggered when something changes in the checkout form. I believe I can use the woocommerce_get_country_locale filter to add the social security number field for Swedish customers. So, inside my woocommerce_checkout_update_order_review hook, I want to trigger the woocommerce_get_country_locale filter. How is this done?
Thanks in advance.
Related
I've add an hidden field on my checkout process plugin. I would like to programmatically change the customer phone number after he submits the order. What would be the correct hook to use, and also where I get the fields as reference, or I need to change the customers information in a different way ?
Thanks
On a page managed by each customer of my Wordpress website, I have a form with multiple fields, not only Wordpress core fields, but also WooCommerce fields, JetEngine fields, etc.
I need to update the user data on another app, via API. I can't find a hook where I can plug my own function, hook fired when all other hook are processed. Because if I hook profile_update, for example, the updated_user_meta calls have not been made, and all the data are not updated yet.
So my thought led me to find a hook which is fired when the form is submit. This way I will be able to get the form fields in my function (called with add_action) and then launch my API calls.
The problem is I can't find a hook which is fired on form submit. Do you have any idea of how I can manage that?
Thanks for your help!
PS: this question is not helping, because it's about admin form, and I'm not on admin side but on customer side, on his profile form.
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.
I have a need to create an advanced product with various discounts and conditional statements. I have tried several plugins including Gravity Forms Product Add Ons and various others but they dont seem to do what I need them to.
My need is I want to have a form the user fills out and I can handle all conditionals and when they hit the Add to cart button it will add their order to cart. I could use create order but not sure because it needs a product ID and I am kind of creating the product on the fly for each customer. I could also create the product as this thread suggests then add to cart but I fear if I manually create a product for each customer that we will have an absurd amount of products.
What would be the best way to create a form and then once filled out and submitted the total and details are sent to cart?
This link was a good resource but doesnt go into detail about the product id or how to do the form. Any guidance on the best way to tackle this?
UPDATE:
Here is a wireframe of what I want to do demonstrating the dynamic text boxes and discount rules. The deposits I am using the Woocommerce Deposits plugin. Just not sure the best way to do this.
So I am trying to set up a site on my localhost. I have selected 2 payment gateways from admin end
Online Payment (Free Shipping)
Cash On Delivery(Free Shipping/Flat COD Charge INR 50 )
Now I have customized all the rules for them. I only need one more rule.
I wish to have a functionality wherein I can enter some pincode/postcode values (through admin panel or maybe in some array in a javascript file or directly into the database, does not matter) of locations where second method is available)
Whenever someone presses continue before confirming order, the checkout form is validated so as to check from the form data if the value entered in post code matches the data (from any of the above methods) and if yes, only then they can continue or I wish to show an error message that
Following payment gateway is not available in your location
If you give me a hint on how to proceed with this, perhaps, I might be able to take it further. I am a bit or a starter in opencart so not much idea about how to proceed. I have sound knowledge of PHP, JQuery and Javascript although. So any and all help will be appreciated.
There are a few different extensions that already exist to do what you want - allow you to restrict shipping methods by various criteria. This one is my personal favorite: http://www.opencart.com/index.php?route=extension/extension/info&extension_id=1614
I managed it with JQuery for the time being. Edited the submit function in the cart.tpl file in catalog->view->theme->ancart (theme name) ->cart folder.
Used a plugin called "Zipcode COD" to enter zipcodes. Edited the response JQuery to hide and show payment options.
Lots of hard coding but does the trick. I will post the code if someone needs.