0

I'm looking at a way to try to set the products of featured stores in Dokan as featured in Woocommerce, but i'm unsure about how to go about this.


function set_featured_products() {

   $args = array( 'featured' => 'true' );
   $featured = dokan_get_sellers( $args );
   
   $args = array( 'featured' => 'false' );
   $not_featured = dokan_get_sellers( $args );
            
  foreach ( $featured['users'] as $seller ) {
    $products_f = get_posts( array(
      'post_type' => 'product',
      'author' => $featured->ID,
      'posts_per_page' => -1
    ) );
    
    foreach ( $products_f as $product) {
      // Set product to be featured or unfeatured based on vendor's featured status
      update_post_meta( $products->ID, '_featured', 'true');
    }
  }
  
   foreach ( $not_featured['users'] as $seller ) {
    $products_nf = get_posts( array(
      'post_type' => 'product',
      'author' => $not_featured->ID,
      'posts_per_page' => -1
    ) );
    
    foreach ( $products_nf as $product) {
      // Set product to be featured or unfeatured based on vendor's featured status
      update_post_meta( $products->ID, '_featured', 'false');
    }
  }
  
}

I've tried this but it doesnt seem to be working

Any help appreciated!

Thanks

Leo Cooper
  • 37
  • 5
  • I'm also not sure how to check the different parts of the code are doing what they are supposed to be doing/where the error lies – Leo Cooper Jan 27 '23 at 19:03

0 Answers0