0

I want mark product featured by id using code

i tried this code but not working

// Your Product ID
$product_id   = 43706;
$ecd_product  = new WC_Product( $product_id );
if( $ecd_product->exists() ){
    $ecd_product->set_featured( true );
    $ecd_product->save();
}

and tried this not working

$product_id   = 43706;
$ecd_product  = new WC_Product( $product_id );
if( $ecd_product->exists() ){
    update_post_meta( $ecd_product->id, '_featured', 'yes' );
}
New contributor
Mohamed Ali is a new contributor to this site. Take care in asking for clarification, commenting, and answering. Check out our Code of Conduct.
2
  • Welcome! Questions about third-party themes and plugins are off-topic here however (you'll notice the "offtopic" in the woocommerce tag you used, meaning questions about WooCommerce are off-topic). You'll need to refer to WooCommerce's documentation or support for guidance on this.
    – YourManDan
    Mar 15 at 18:05
  • you need to ask this in a WooCommerce community, WooCommerce and other 3rd party plugin/theme dev support is off topic and not in this stacks scope.
    – Tom J Nowell
    Mar 15 at 18:32

0