Theme and Plugin Support
-
AuthorPosts
-
-
March 28, 2022 at 8:36 PM #135849odedtalmonParticipant
Hello,
Is it possible to update a product vendor programmatically? Do you have a built-in function that does that?
This doesn’t work:update_post_meta($product_id,'choose_vendor',$value);
Copyupdate_post_meta($product_id,'_choose_vendor',$value);
CopyThanks
-
March 29, 2022 at 10:20 PM #135893Raju The Cool GuyKeymaster
Hi,
You can check by using this waywp_delete_object_term_relationships($product->ID, $WCMp->taxonomy->taxonomy_name); wp_set_object_terms($product->ID, (int) $term_id, $WCMp->taxonomy->taxonomy_name, true);
CopyThanks
-
April 3, 2022 at 9:11 PM #136036odedtalmonParticipant
Hello again,
I don’t understand what needs to go in the $WCMp->taxonomy->taxonomy_name variable.
The term id is this: $vendor_term_id = $vendor->get_term_id(); ?Thanks
-
April 5, 2022 at 12:18 PM #136113Raju The Cool GuyKeymaster
Hi,
Taxonomy is the same as woocommerce. In our case it is dc_vendor_shop.
2nd one is right
Thanks -
April 5, 2022 at 3:28 PM #136119odedtalmonParticipant
I tried to run this code:
$product_id = 45227;
$vendor = get_wcmp_vendor( 8096 );
$vendor_term_id = $vendor->get_term_id();wp_delete_object_term_relationships( $product_id, ‘dc_vendor_shop’ );
wp_set_object_terms( $product_id, $vendor_term_id, ‘dc_vendor_shop’, true );That didn’t change the vendor for the product. What should I do?
Thanks.
-
April 5, 2022 at 9:08 PM #136156Raju The Cool GuyKeymaster
Hi,
check this code https://github.com/wcmarketplace/dc-woocommerce-multi-vendor/blob/master/classes/class-wcmp-product.php#L965
you might put the wrong term id. check that line. Do the same as mentioned above.
Thanks -
April 13, 2022 at 11:18 AM #136410odedtalmonParticipant
Hello,
I still don’t understand what the term for that vendor actually is. I am using the built in function of the vendor classget_term_id()
Copy, how could that be wrong? What is the correct term id that should be places in that function?
In any case, I tried updating to code according to the example you sent and it’s still not working.
Here’s the code:$vendor_term_id = $WCMp_Vendor->get_term_id();
$term = get_term( $vendor_term_id, $WCMp->taxonomy->taxonomy_name );if( $term ) {
wp_delete_object_term_relationships( $product_id, $WCMp->taxonomy->taxonomy_name );
wp_set_object_terms( $product_id, (int) $term->term_id, $WCMp->taxonomy->taxonomy_name, true );
}$vendor = get_wcmp_vendor_by_term( absint( $term->term_id ) );
if( !wp_is_post_revision( $product_id ) && $vendor ) {
$WCMp_Product = new WCMp_Product();
// unhook this function so it doesn’t loop infinitely
remove_action( ‘save_post’, ‘process_vendor_data’ );
// update the post, which calls save_post again
wp_update_post( array( ‘ID’ => $product_id, ‘post_author’ => $vendor->id ) );
// re-hook this function
add_action( ‘save_post’, array( $WCMp_Product, ‘process_vendor_data’, $product_id ) );
} -
April 13, 2022 at 11:19 AM #136411odedtalmonParticipantThis reply has been marked as private.
-
April 13, 2022 at 7:49 PM #136423NerdySupportExpert MoumitaKeymasterThis reply has been marked as private.
-
-
AuthorPosts
The topic ‘Updating product vendor programatically’ is closed to new replies.