Allow vendors to publish the products whichi have been published already.

WCMp Advanced Frontend Manager

Allow vendors to publish the products whichi have been published already. Resolved

Viewing 13 reply threads
  • Author
    Posts
    • #88373
      ryu
      Participant

      I don’t allow vendors to publish a new product without admin aprroval.
      But, I want to allow vendors to edit and publish a publishd product without being pending status.
      Can I do that?

      ↓This code is not working.

      function on_all_status_transitions( $new_status, $old_status, $post ) {
          if ( $new_status == 'ppending' && $old_status == 'publish' ) {
      		$my_post = array(
      			'ID' => $post_id,
      			'post_status' => 'publish',
      		);
      		wp_update_post( $my_post );
          }
           return $post;
      }
      add_action(  'transition_post_status',  'on_all_status_transitions', 10, 3 );
      Copy
    • #88631

      @ryu, you need to use this code, to publish the edited product, if the Publish option is not given :

      /**************  product published after 1st time permission ****************************/
      add_action( 'wcmp_process_product_object', 'approved_vendor_action' , 10 , 2 );
      function approved_vendor_action( $product , $data ){
       if ( $_SERVER['REQUEST_METHOD'] === 'POST' ) {
         if( metadata_exists( 'post', $product->get_id(), 'approved_manually_vendor' ) ){
           $product_value = get_post_meta( $product->get_id(), 'approved_manually_vendor', true );
             if( $product_value == 2 ){
             $post_data = array(
               'ID' => $product->get_id(),
               'post_status' => 'publish',
               );
             wp_update_post( $post_data );
           }
         } else{
           update_post_meta( $_POST['post_ID'], 'approved_manually_vendor', 1 );
         }
       }
      }
      
      function save_product_from_admin_end( $post_id ) {
       $product = wc_get_product( $post_id );
       $product->update_meta_data( 'approved_manually_vendor', 2 );
       $product->save();
      }
      add_action( 'woocommerce_process_product_meta', 'save_product_from_admin_end' );
      Copy
      • #90368
        ryu
        Participant

        Hi, thanks your awesome code.

        but I have a problem.
        When vendors create a new product by duplicating their product, which has been still published and has a post meta( ‘approved_manually_vendor = 2’), the product will be published without an admin approval.
        Can I avoid that problem?

    • #90423
      sumit singh
      Moderator

      Hi, Kindly use following code,

      add_action( 'wcmp_process_product_object', 'approved_vendor_action' , 10 , 2 );
      function approved_vendor_action( $product , $data ){
       if ( $_SERVER['REQUEST_METHOD'] === 'POST' ) {
         if( metadata_exists( 'post', $product->get_id(), 'approved_manually_vendor' ) && metadata_exists( 'post', $product->get_id(), 'approved_vendor' ) ){
         	$vendor_id = get_current_vendor_id();
           $product_value = get_post_meta( $product->get_id(), 'approved_manually_vendor', true );
           $product_vendor = get_post_meta( $product->get_id(), 'approved_vendor', true );
           $vendor = is_array( $product_vendor ) ? $product_vendor : array();
      	if( $product_value == 2 && in_array($vendor_id, $vendor) ){
      	   $post_data = array(
      	     'ID' => $product->get_id(),
      	     'post_status' => 'publish',
      	     );
      	   wp_update_post( $post_data );
          }
         } else{
           update_post_meta( $_POST['post_ID'], 'approved_manually_vendor', 1 );
         }
       }
      }
      
      function save_product_from_admin_end( $post_id ) {
       $product = wc_get_product( $post_id );
       $vendor_id = get_current_vendor_id();
       $product_vendor = get_post_meta( $product->get_id(), 'approved_vendor', true );
       $vendor = is_array( $product_vendor ) ? $product_vendor : array();
       $product->update_meta_data( 'approved_manually_vendor', 2 );
       $product->update_meta_data( 'approved_vendor', array_merge($vendor,array($vendor_id)) );
       $product->save();
      }
      add_action( 'woocommerce_process_product_meta', 'save_product_from_admin_end' );
      Copy
    • #91352
      ryu
      Participant

      Thnak you very much , but it not working… :_(
      (@NerdySupportExpert Moumita’s code is good working.)

      In addition to @NerdySupportExpert Moumita’s code, I want another function.
      When vendors duplicate their own published post, which has post_meta( ‘approved_manually_vendor’, 2 ) , I want to remove that post_meta of the duplicated post. so vendor can’t publish the duplicated post without admin approval.

      With @NerdySupportExpert Moumita’s code, the approved posts and duplicated post also has post_meta( ‘approved_manually_vendor’, 2 ), so vendor can publish the duplicated post( = new product ) without admin approval….

    • #91440
      sumit singh
      Moderator

      hi, use the

      do_action( 'woocommerce_product_duplicate_before_save', $duplicate, $product );
      Copy

      action to remove

      post_meta( ‘approved_manually_vendor’, 2 )
      Copy

      for duplicated published product

    • #91510
      soovie.sourcing
      Participant

      Hi I have used the code posted by Moumita to allow vendors to publish posts that have been approved and published by admin.
      But I also want duplicated products to be approved for first publish, as the other user has asked for.

      But I am lost with the last posting by Sumit – where should I add the 2 codes you provided?
      do_action( ‘woocommerce_product_duplicate_before_save’, $duplicate, $product );
      post_meta( ‘approved_manually_vendor’, 2 )

      I used the following code as Moumita has provided
      /************** product published after 1st time permission ****************************/
      add_action( ‘wcmp_process_product_object’, ‘approved_vendor_action’ , 10 , 2 );
      function approved_vendor_action( $product , $data ){
      if ( $_SERVER[‘REQUEST_METHOD’] === ‘POST’ ) {
      if( metadata_exists( ‘post’, $product->get_id(), ‘approved_manually_vendor’ ) ){
      $product_value = get_post_meta( $product->get_id(), ‘approved_manually_vendor’, true );
      if( $product_value == 2 ){
      $post_data = array(
      ‘ID’ => $product->get_id(),
      ‘post_status’ => ‘publish’,
      );
      wp_update_post( $post_data );
      }
      } else{
      update_post_meta( $_POST[‘post_ID’], ‘approved_manually_vendor’, 1 );
      }
      }
      }

      function save_product_from_admin_end( $post_id ) {
      $product = wc_get_product( $post_id );
      $product->update_meta_data( ‘approved_manually_vendor’, 2 );
      $product->save();
      }
      add_action( ‘woocommerce_process_product_meta’, ‘save_product_from_admin_end’ );

    • #91544
      sumit singh
      Moderator

      Hi, you need to add the codes shared by moumita and as well as you have to use the following action to check if duplicate product has ‘approved_manually_vendor’ meta then remove it.

      do_action( 'woocommerce_product_duplicate_before_save', $duplicate, $product );
      Copy

      since the above action is invoked just before the duplicate product save.

    • #91556
      soovie.sourcing
      Participant

      Hi, I tried adding do_action( ‘woocommerce_product_duplicate_before_save’, $duplicate, $product );

      But it still doesn’t work..:(
      Duplicated products are published without admin approval.

    • #91592
      sumit singh
      Moderator

      Hi, can you please share the code you have added. So we can help you.

    • #91632
      soovie.sourcing
      Participant

      Hi, I used the code Moumita shared on this post AND do_action( ‘woocommerce_product_duplicate_before_save’, $duplicate, $product );

    • #91722
      sumit singh
      Moderator

      Hi, add the codes shared by moumita and also add the following coddes:-

      add_filter( 'woocommerce_duplicate_poduct_exclude_meta', 'remove_meta_before_duplicate' );
      function remove_meta_before_duplicate( $exclude ) {
      $new = array( 'approved_manually_vendor' );
      return array_merge( $new, $exclude );
      }
      Copy

      the above code will remove meta ‘approved_manually_vendor’ when vendor create duplicate product.

    • #91732
      soovie.sourcing
      Participant

      Hi Sumit,

      I am sorry but the code you shared with me is still not working.
      With Moumita’s code, vendors can publish without admin approval for already approved products, but if I duplicate the product page on vendor front it still gets published automatically without first time approval by admin. 🙁

    • #91751
      soovie.sourcing
      Participant

      Hi~~ there was a typo in your code (poduct)- found it and it works!!
      Thanks so much!! 🙂

    • #91754

      Great to know that @soovie.sourcing

      I hope you are satisfied with our assistance and plugin. A 5/5 review here- https://wordpress.org/support/plugin/dc-woocommerce-multi-vendor/reviews/#new-post , would be a great way to share your experience with others.
      This motivates us to continue providing the best experience possible and also helps others know how WC-Marketplace can make their life easier.

Viewing 13 reply threads

The topic ‘Allow vendors to publish the products whichi have been published already.’ is closed to new replies.

Buy all Marketplace addons together, check out our Bundle

Buy at Slashed Price