List all Customer Coupons in Woocommerce

Recently I was tasked with figuring out how to do something that I figured would be easy but was deceptively hard – displaying all the coupons for a customer in woocommerce. A client wanted to show a user all their coupons, and surprisingly this wasn’t built into woocomerce already. To solve the problem, I created a custom page template and ran a query on the wp_postmeta table to get the ids of all of the coupons that were linked to the customer’s email. Then I ran a WP Query to get the posts and used the get_post_meta function to display the various coupon meta fields and build the data. Here is an overview of the technique using generic information.   Get The Current User Data global $current_user, $woocommerce; //get current user and woocommerce global variables get_currentuserinfo(); // get current logged in user info $current_user = wp_get_current_user(); // grab the logged in user $user_id = $current_user->ID; // grab the logged in users id $email = $current_user->user_email; // grab the logged in user email   Run a query on the meta table, targeting the coupons linked to the customer’s email and create an array of the ids returned // Run a query on the postmeta table to get the id of every coupon that has the email in the customer_email restrictions $couponlist = $wpdb->get_results("SELECT `wp_postmeta`.`post_id` FROM `wp_postmeta` WHERE `wp_postmeta`.`meta_key`

Woocommerce Search Orders By Item or Sku Plugin

A while back a client, by which I mean every client I’ve ever had with a woocommerce store on their site, asked me if they can search through their orders to find all orders that contain a certain item. As my introduction to Woocommerce was a little over a year ago, I knew the functionality wasn’t there but I wasn’t sure how to add it. Being the good forward thinker that I am, I put it on my “Deal with this eventually list” and proceeded to move on to issues that had deadlines and that clients were actually paying me to fix for them. In a few moment of downtime the other week, I decided to revisit the issue. Much to my delight, I found some definitive answers on how to make this happen. This recent post on Stack Exchange contained code and a solution cobbled together by 3 or 4 different users. I grabbed it, tested it on a few of my test sites, and gleefully found that it added the exact ability so many of my clients had been looking for. Searching for these answers before last month turned up many scarce results, so I decided to wrap the code in an easy to install plugin and throw it out there for anyone who might need it. Please be aware of a few things. I did not write this code, merely compiled the solution from the stack exchange thread into a plugin so all you have to do is install

Woocommerce CSV Export HTTP POST

I was recently tasked with writing a script to export the data from a woocommerce database, rearrange it, and email it to a warehousing partner automatically. The first part was pretty easy – writing the script, rearranging the sample data, and emailing it automatically when the script was run. The second part was a bit more complex. The client had the GNU licensed CSV Customer/Order Export extension for Woocommerce. Unfortunately, it wasn’t working as expected. The client  had already purchased a support license, but I hadn’t heard back from the support techs yet and was running far too close to deadline for my own comfort. The extension is set up to export to FTP or HTTP POST automatically and I decided to integrate that and accept the file it exports in the post instead of just using SQL to dig into the complex database structures and grab the data (more on that in another post). There was only one problem, it doesn’t actually submit a file with the HTTP POST option. The Solution Since I solved the problem, I figured I would share the solution for any other coder having the same issue. I’ve also asked support staff to update the documentation, as knowing one simple fact would have saved me HOURS of work. The HTTP POST option from CSV Customer Order Export sends a stream of CSV formatted data, but not an actual CSV file. I had built a script that was capable of taking a submitted file and then running code on