I have a custom payment gateway in WooCommerce, and I want to display additional payment fields when users select this payment method on the checkout page. Currently, I am using the payment_fields() method, but I’m encountering issues with the form display. Can someone guide me on how to properly show my custom payment fields when the user clicks on my payment method during the checkout process?
public function payment_fields()
{
$cc_form = new WC_Payment_Gateway_CC();
$cc_form->id = $this->id;
$cc_form->supports = $this->supports;
$cc_form->form();
}
If I load the payment_fields() field in the construct as $this->payment_fields(), the form is displayed at the top of the page, but I do not like this. When my payment method is clicked, I want this form to appear instead of the description text. If I don’t add it to the construct, the form doesn’t appear anywhere.
2
Answers
First, try to add/replace in your constructor function:
Then try to add/replace (after the constructor function):
To finish, try to add the following outside
plugins_loaded
hooked function *(that handles your custom payment gateway class). Inside the function, replaceyour_payment_id
with the correct payment method ID.It could work.
I’m currently having the similar issue with payment_fields method. My custom payment field is not showing up during checkout. Were you able to resolve it? If so could you please let me know the steps you followed? Thank you!