WordPress Codesnippets

woocommerce get categories by product id


This code retrieves the categories associated with a product and then prints out each of the category names to the screen. The first line of code gets the ID of the product and the second line retrieves the product categories associated with the ID. Finally, a foreach loop is used to iterate through each of the categories and echo out the name of the category.

Was this code snippet helpful?

Leave a Reply

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

Programmatically save post

This code creates a WordPress post with the values of the ‘post_title’ and ‘post_content’ variables. It sets the post status to ‘publish’ and the author

Read More »

Create order programmatically

This code creates a new post in the WordPress database with post type ‘shop_order’, post title ‘Order #12345’, post status ‘wc-processing’, and ping status ‘closed’.

Read More »