WooCommerce: See What’s Inside the Cart Array (print_r)

So many times I needed to “play” with Cart contents in order to modify the default behaviour (such as removing a columns, hide the sale price to prices, hide an item, etc.).

There is a great PHP function that always helps – it’s called print_r and you can use this to “see” what’s inside the cart array, so that you can return certain information in a message for example.

A bit advanced, but as you grow your WooCommerce coding skills, you will use this a lot 🙂 Continue reading WooCommerce: See What’s Inside the Cart Array (print_r)

WooCommerce: Tax Exempt User Based on Checkout Field Value

There is a nice WooCommerce function you can use to exempt someone from Tax/VAT calculations. You could, for example, enable exemption once they enter a Tax/VAT number, or maybe if they specify a given ZIP code.

Such function is called set_is_vat_exempt(), and together with a little trick to “get” a checkout field on the go, the snippet is pretty simple to build and test. Enjoy!

Continue reading WooCommerce: Tax Exempt User Based on Checkout Field Value

WooCommerce: See What’s Inside the Order Array (print_r)

When coding in PHP for WooCommerce, sometimes you’ll need to know what’s inside the “Order Array”, so that you can use its elements to print some custom message on the thank you page, or maybe modify its default behaviour.

There is a great PHP function that helps a lot – it’s called print_r() and you can use this to “see” what’s inside the order array 🙂 Continue reading WooCommerce: See What’s Inside the Order Array (print_r)

WooCommerce: Check if User Has Bought Product in the Last 365 Days

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

WooCommerce: “Buy One Get One” (BOGO)

Case scenario: if you add a product ID to cart with a specific, you want another product automatically added to cart (Buy One Get One, or “BOGO”).

This second product should have price = 0 if you wish to completely give it away, or maybe a set sale price. It should also be set to “hidden” because maybe you want to hide this free product from the shop and only gift it when the first one is added to Cart.

Also, if you remove product 1, the gifted product should go away from the Cart too. So here follows the PHP snippet of course!

Continue reading WooCommerce: “Buy One Get One” (BOGO)