How to change / delete product short description in Woocommerce
I use
$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 communityHow to change / delete product short description in Woocommerce
I use
$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');
Th function 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 set_short_description()
:
// 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.
Related: How to programmatically grab the product description in WooCommerce?
You should have the $product
global available to you, which lets you call set_short_description and then save to store the changes:
$product->set_short_description('some description');
$product->save();
wp_set_object_terms
doesn't tell us anything, when we don't know how exactly you are using it. In what function, with what parameters, retrieved from where? Please update your question accordingly. Many thanks – leymannx May 11 '19 at 7:55