Patrick's Programming Blog

Notify Admin of Customer Address Change in WooCommerce

woocommerce banner
  1. Blogging for Benjamin Competition
  2. Why I'm Grateful to Work on the Web
  3. 24 Pull Requests
  4. Update Downloadable Product's Expiration Date in WooCommere
  5. Get Lost in the Flow and Work for More Than a Salary
  6. Why A Plugin's Popularity Matters
  7. Why You Should (Or Shouldn't) Use Premium Plugins
  8. WooCommerce Terms & Conditions
  9. Only Ship to Continental United States with WooCommerce
  10. Just Talk
  11. Why I Love Jetpack
  12. Making Jetpack Better
  13. Remove Billing Address for Free Virtual Orders in WooCommerce
  14. Notify Admin of Customer Address Change in WooCommerce
  15. Open Your Self Up To New Possibilities
  16. 2013 Resolutions Review
  17. Create a Community
  18. Tips for Starting a Community
  19. The Intent of Goals
  20. Create The Ultimate Invoicing System Using WooCommerce
  21. Change From Address in Ninja Forms
  22. Work With People Who Inspire You
  23. Contact Form 7 & MailPoet Integration
  24. Monotasking
  25. Giving Back to The Community
  26. Adding Fuctionality to Lean Plugins
  27. Choose Stripe For a Payment Gateway
  28. A Dip Into Entrepreneurship
  29. Reward Yourself
  30. Blogging for Benjamin Plugin
  31. Blogging for Benjamin Wrap Up

One of the extensions that I love working with at WooThemes is the Subscriptions extension for WooCommerce. It's probably the most complex extension we have which can make troubleshooting issues challenging but that's offset because the developer also has the best documentation bar none.

The number of possibilities with Subscriptions are really endless. One of my favorite examples is HDPiano.com which sells virtual memberships to learn how to play piano. There's also plenty of users who sell tangible products each month. I just ran into a user who creates fancy shipping labels in Photoshop and uses those labels to ship her products.

The only problem in her case was that she creates the shipping label before the new order comes in so she needed a way to be notified of a customer changing their address before the actual order came in. This is where some of those awesome WooCommerce hooks come in.

Address Change Hook

In this case I'm going to be using the woocommerce_customer_save_address action and add some additional functionality when the user changes their address on the My Account page.

I’m including the plugin for you to look at the code but you can also go the plugins home page and download it, extract the zip file, and upload the folder to your /wp-content/plugins/ directory of your site.

In this case I just get all of the user data using the really useful get_currentuserinfo() function and then get the customers address using the WC_Customer class. Then send all of the information using the wp_mail function. You might notice that I didn't add any filters in this plugin and I wrote the address in a standard US style. That's because this is a really quick snippet. If I wanted this to be more modular for the future I would add extra filters to accommodate these needs.

End Result

So what does it look like at the end? Why a simple email in your inbox.

Exploring

While we don't offer customization support at WooThemes there is a lot of value in occasionally doing customizations like this. They are opportunities to dig into the code and learn a bit more about our huge WC system while helping a customer at the same time. And then if you can make the information publicly available (like this blog post) then it's indexable for future users. Win win in my opinion.

Exit mobile version