Support » Plugin: Dokan - Best WooCommerce Multivendor Marketplace Solution - Build Your Own Amazon, eBay, Etsy » Adding a Dokan product dynamically and setting the Vendor

  • Resolved teamf

    (@teamf)


    Hi, I need to add a Dokan product dynamically on the click of a button. I have done this successfully with the following code but need help with setting the Vendor of the product created. By default, it creates the product under the Admins username but I want to set the Vendor to another user. Is there a Vendor attribute I can set? Hope someone can help.

    $objProduct = new WC_Product();
    $objProduct->set_name($_POST[‘jobTitle’] . ” TEST” );
    $objProduct->set_status(“publish”);
    $objProduct->set_catalog_visibility(‘hidden’);
    $objProduct->set_description(“Product Description”);
    $objProduct->set_sku(‘1234’]);
    $objProduct->set_price(20);
    $objProduct->set_regular_price(15);
    $objProduct->set_manage_stock(true);
    $objProduct->set_stock_quantity(10);
    $objProduct->set_stock_status(‘instock’);
    $objProduct->set_backorders(‘no’);
    $objProduct->set_reviews_allowed(true);
    $objProduct->set_sold_individually(false);
    $objProduct->set_virtual(‘yes’);
    $objProduct->set_category_ids(array(1,2,3));
    $new_product_id = $objProduct->save();

Viewing 2 replies - 1 through 2 (of 2 total)
  • Plugin Contributor Edi Amin

    (@ediamin)

    Hi @teamf Just update the post_author will set the vendor for that product,

    
    $args = [
        'ID' => $new_product_id,
        'post_author' => $vendor_id
    ];
    
    wp_update_post( $args, true );
    
    • This reply was modified 8 months, 3 weeks ago by Edi Amin.

    That is brilliant thanks, I just tried it and it works!

    Appreciate your help and fast response. We are very pleased with the Dokan product on our test site, so are looking at getting the pro version now.

Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘Adding a Dokan product dynamically and setting the Vendor’ is closed to new replies.