Ask your WordPress questions! Pay money and get answers fast! Comodo Trusted Site Seal
Official PayPal Seal

Billing Address Fields on Pay-Order Page (Woocommerce) WordPress

  • REFUND REQUESTED

Hi,

I send my customers custom invoices using woocommerce by adding a new order through the admin dashboard. I fill in the customers email address and click send an invoice to that customer so that they can pay directly through my website using any of my payment processing options. I don't always have my customers billing address so I would like them to be able to enter it themselves on the woocommerce Pay-Order page.

Here is an example order:

https://astrobotanicals.com/checkout/order-pay/598/?pay_for_order=true&key=order_5563cda15664c

(Caution! Do not actually pay for this example order you won't be refunded. I have attached a screenshot of the order page linked above in-case someone hits the pay button.)

I want that page to display the customers Billing address fields and be able to fill it in if no billing data already exists. I hope this should be pretty straightforward, I have tried to solve this myself using these links:

http://docs.woothemes.com/document/tutorial-customising-checkout-fields-using-actions-and-filters/

https://support.woothemes.com/hc/en-us/articles/203182373-How-to-add-custom-fields-in-user-registration-on-the-My-Account-page

But I don't know how to code in PHP so I haven't had any success with my attempts. I would ideally like replace the contents of the woocommerce/checkout/form-pay.php file with the new code so that I can place it in my themes folder without having to worry about updates over-writing it (I know where to place it, that's not part of my question) - ideally I don't want to have to append any code to my functions.php file.

Bonus addition if you don't mind, it would be nice if I could get the product thumbnail to display next to the product line too.

Thanks!

Answers (1)

2015-05-26

John Cotton answers:

Is there something odd about your setup?

This HTML


<div class="col2-set" id="customer_details">
<div class="col-1"></div>
<div class="col-2"></div>
</div>


just before the payment choices should have the billing and shipping details in. From a quick look at the plugin code, unless you have cancelled the 'woocommerce_checkout_billing' action or created a blank form-billing.php, you should have some extra HTML in there at the least (and probably the whole billing form).

Have you made changes or has you theme made changes?


jamiolee comments:

Thanks for pointing that out, that was part of my attempt to see if I could get it to work myself. I have now removed that code and flushed the cache.


John Cotton comments:

You were probably on the right track.

However, from a scan of the code, I don't think there is a neat way to do what you want.

You could override the form-pay.php template and call the wc_billiing_fields action.

However, form-pay processes the form very early and I can't see any neat hooks in there that you could use to grab the posted back billing data (WC isn't going to do it for you since it's not expecting that data at the pay point).

There is a filter (woocommerce_valid_order_statuses_for_payment) which you could use to trigger your own saving of the billing data, but that seems a bit messy to me.

The alternative would be to have the billing form somewhere else on the page (in a separate <form> tag) and save any changes via ajax.

You'd need to lock the payment selection until that was completed so this route does become quite complicated.




jamiolee comments:

This is more complicated than I thought it would be, I'll have to retract my question then and I'll use Quick Books instead.