How to change / delete product short description in Woocommerce
$short_desc = $post->post_excerpt;
to read the property but I cant change it with
wp_set_object_terms($post->ID, $post->post_excerpt, 'new excerpt');
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It only takes a minute to sign up.Sign up to join this community
wp_set_object_terms() will not work to set post object properties.
To add/update/delete product short description there is mainly 2 ways:
1) the WordPress way from a post ID using
wp_update_post() function this way:
$product_id = $post->ID; // or get_the_id() or $product->get_id() (when $product is available); // The product short description (for testing) $new_short_description = "<strong>Here</strong> is is the product short description content." // Add/Update/delete the product short description wp_update_post( array('ID' => $product_id, 'post_excerpt' => $new_short_description ) );
2) The WooCommerce way from the
WC_product Object using
// Optional: get the WC_product Object instance from the post ID $product_id = $post->ID; // or get_the_id() $product = wc_get_product( $product_id ); // The product short description (for testing) $new_short_description = "<strong>Here</strong> is is the product short description content." $product->set_short_description( $new_short_description ); // Add/Set the new short description $product->save(); // Store changes in database
To delete the product description you will set an empty string.