user51315
user51315

Reputation: 1

List products by their author - Woocommerce Wordpress

I do not know whether you can help me or not but I need your help.

I have tried a lot of things to list products by their author on my web-site, however, I failed.

I want it so that when people click on author's profile, they can see the author's products.

If anyone knows to write this code, please help me.

Thanks in advance.

Upvotes: 0

Views: 4497

Answers (1)

Christian
Christian

Reputation: 19750

Products in WooCommerce are simply posts with a custom post type. As long as you assign the author capability (example taken from here):

add_action('init', 'wpse_74054_add_author_woocommerce', 999 );

function wpse_74054_add_author_woocommerce() {
    add_post_type_support( 'product', 'author' );
}

Then it's trivial to list posts by an author, using code like this:

$args = array(
    'author'     =>  $author_id,
    'post_type'  => 'product'
);

$author_posts = get_posts( $args );

Upvotes: 3

Related Questions