Add Buddypress user fields to Woocommerce tabs

I’ve recently finished a project where I had to combine a custom WordPress theme with the plugins Buddypress and Woocommerce.

Even though the plugins are easily set up (one click installs), setting it up to specifically adhere to whatever the clients want them to do is something else. I set up a new design for both Buddypress and Woocommerce, along with many custom made functions.

One of the things the site was supposed to do, was to give certain members new roles (based on whether or not they subscribed to the site). The user would then have the ability to sell his or her own products in the site-wide Woocommerce shop.

This particular challenge was to combine Buddypress’s user fields with Woocommerce, and display it inside a product tab.

So, how do you combine Buddypress user fields with product tabs in Woocommerce?

Luckily for us, it doesn’t really require that much coding. Let’s make it happen.

First, let’s create the Woocommerce tabs.

We need some stuff inside the tabs too!

Let’s put conditional tabs into the mix. In our case, we’ll alter the tab-code to only show the product tabs in certain categories. We’ll give it an array so we can do more than just one category.

Revisiting the tab-code, we’ll enter has_term with an array to the following code line. Change the ‘Category name 1’ etc. to your category name and you’re all set.

Now we have the Woocommerce tabs all set up, we’ve even made them conditional to only shop up at certain category products. Now lets make the content of the tabs draw from the power of Buddypress user fields.

We’re going to have the code draw the Buddypress user field from the Author of the product.

Needless to say, the user fields must be filled out in order to show anything in the tab.

Once you change ‘User field name’ to the field name you want to show, you’re good to go. There’s not much more to it. You can also change get_the_author_id() to a specific user ID, in turn getting that user’s field to be displayed in every tab.

Let’s check out the full code with everything tied together.

Insert the code in your function.php folder, and you’ve got some conditional Buddypress user fields showing up in your Woocommerce product tabs.

Leave a Reply

Your email address will not be published. Required fields are marked *