Restricting content based on product purchase in WooCommerce




Screencasts – WP Theme Tutorial show

Summary: Last time I wrote about dealing with issues with WooCommerce custom statii when I set up my Woocommerce store. Today we're going to take a look at another tweak I made to WooCommerce. My book has 2 packages. The first is the book and the second is the book plus interviews with other business owners and freelancers about how they run their business. It costs extra to purchase the book and videos so I want to restrict access only to those that have purchased the access. WooCommerce already has the Groups Plugin which allows content restriction but it needs the WooCommerce Subscriptions plugin as well. See it's geared towards monthly payment and memberships so not quite what I need. All I want is if you have purchased the book and videos you get access to the interviews. 1 function To achieve this all we need is one function called `wc_customer_bought_product( $email, $user_id, $product_id )'. wc_customer_bought_product takes 3 parameters. $email - The email of the user we are checking $user_id - The id of the user we are checking $product_id - The ID of the product we are checking the purchase for For my book the product variation with the books and video has the ID of 4388. So that means I need to get the email and user id for the current user.