Viewing 10 replies - 1 through 10 (of 10 total)
  • Hello,

    Thanks again for reaching out. To be sure that I understand your query, you want to know how do you change the vendor associated to any product. If I got it right, you can do so by changing the term ID and author ID for the product. If I went wrong, please elaborate your query further.

    Let me know if that helps.

    Regards,
    Sandeep

    Thread Starter _eldar_

    (@_eldar_)

    Hello!

    For example, the product #1 (ID = 22) belongs to vendor #1 (ID = 44). I want to make the copy of this product #1 (the ID the copy product = 23) and make the copy belongs to to vendor #2 (ID = 45). Which PHP function can help me?

    Hello Eldar,

    Thanks, as far as I see when you duplicate a product, everything copies over including the vendor allocated to the original product. Though all details can be edited from the wp-admin manually. Are you looking for a way such that when you create a duplicate product it is assigned automatically to a different vendor?

    If your answer is yes, then how would this mapping work out when there are more than 2 vendors on your site. If there are only 2 then it would always get allocated to other one with the automated process.

    Awaiting your response.

    Regards,
    Sandeep

    Thread Starter _eldar_

    (@_eldar_)

    Hello Sandeep,

    Yes, I want to change the vendor using PHP script without admin page. How is it possible to do?

    Hello Eldar,

    suppose,
    $product_id = <id of the product>
    $vendor_term = <term id of the dc_vendor_shop taxonomy>

    then following is the php script to change vendor of a product,

    $term = get_term( $vendor_term , ‘dc_vendor_shop’ );
    wp_delete_object_term_relationships( $product_id, ‘dc_vendor_shop’ );
    wp_set_post_terms( $product_id, $term->name , ‘dc_vendor_shop’, true );

    $vendor = get_wcmp_vendor_by_term($vendor_term);
    if ( ! wp_is_post_revision( $product_id ) ) {
    // update the post, which calls save_post again
    wp_update_post( array(‘ID’ => $post_id, ‘post_author’ => $vendor->id) );
    }

    Let me know if that helps.

    Regards,
    Sandeep

    Thread Starter _eldar_

    (@_eldar_)

    Hello Sandeep,

    Sorry, I know only the user ID. That user is vendor. How to get his “term id”?

    Hello Eldar,

    Let me explain both these:

    $user_id = user id;
    $term_id = get_user_meta($user_id, ‘_vendor_term_id’, $single);

    $term_id is the term id of that vendor.

    Let me know if that helps.

    Regards,
    Sandeep

    Hello Eldar,

    Just thought to check in if the shared info was useful.

    Regards,
    Sandeep

    Thread Starter _eldar_

    (@_eldar_)

    Hello Sandeep,

    that works! thank you!

    Hello Eldar,

    Thanks for the kind update. We were away for a week long vacation. I hope you have checked the latest version of the plugin. Let me know if the new features help your plans. Of course, new ideas from your end are more then welcome.

    Regards,
    Sandeep

Viewing 10 replies - 1 through 10 (of 10 total)
  • The topic ‘PHP quetion’ is closed to new replies.