There is a native, handy way to get a WooCommerce customer’s last order: wc_get_customer_last_order( $customer_id )
This time, I want to write some custom code to get the second last order instead. We will indeed reuse most of the above function code and change it slightly. Enjoy!
Continue reading WooCommerce: Get Customer Second Last Order
We’ve already covered a little about address formats when we added a custom House Number field to the WooCommerce Checkout page.
Address formats define the way Billing and Shipping addresses are formatted for the end user. Addresses show on the order received / thank you page, on transactional emails and on some My Account pages, and look like this:
Now, what if you wanted to move the “company” before the customer name, or maybe have “address 1” and “address 2” on the same line, or move “postcode” to the last line? Well, thankfully there is a neat WooCommerce filter called “woocommerce_localisation_address_formats” that allows us to do just that – reformat any address for any country we wish. Enjoy!
Continue reading WooCommerce: Change Address Format For a Specific Country
This is a neat custom function that you can use in your WooCommerce customization. It can be helpful to know the list of orders placed by the current user ID, for example, if they are in their “My Account” page and you have a custom tab where you want to show e.g. only failed orders. Sooner or later this is something you’ll need. Enjoy!
Continue reading WooCommerce: Get Current User Orders By Status
Today’s snippet is a helpful shortcut for getting the list of customers in your WooCommerce website. This may be necessary during customization, especially if you need tailor-made features for administrators and shop managers in the backend or frontend.
How did I find out about the solution below? Well, our job is mainly copy/paste from online forums or read thoroughly the WooCommerce core files on a daily basis – so it must’ve been one of the two. Enjoy!
Continue reading WooCommerce: Get List Of All Customers
When an order is placed in WooCommerce, you might want to change/add something in the User Meta programmatically.
For example, you could “check” a custom checkbox in the User Profile. Or maybe assign the User Twitter username. And so on 🙂
Continue reading WooCommerce: Update User Meta After a Successful Order
A few snippets ago we introduced the magic WooCommerce inbuilt function “wc_customer_bought_product” – automatically, with a single line of PHP, you can find out if the user has already purchased a product ID.
But when building my new #BloomerArmada section, I had to know if a user purchased a product ID in the last 365 days… so I rewrote the function, changed its name and added a little edit to it – easy peasy!
Continue reading WooCommerce: Check if User Has Bought Product in the Last 365 Days