如何在WooCommerce中更改/删除产品简短说明

时间:2019-05-11 作者:Kamran Asgari

如何在Woocommerce中更改/删除产品简短描述

我使用

$short_desc = $post->post_excerpt;
阅读属性,但我无法更改

 wp_set_object_terms($post->ID, $post->post_excerpt, \'new excerpt\');

2 个回复
最合适的回答,由SO网友:LoicTheAztec 整理而成

Th函数wp_set_object_terms() 无法设置后期对象属性。

添加/更新/删除产品简短描述there is mainly 2 ways:

(1)the WordPress way 来自post ID 使用wp_update_post() 功能如下:

$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 wayWC_product Object 使用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

delete 您将设置的产品描述empty string.

相关:How to programmatically grab the product description in WooCommerce?

SO网友:Alexander Holsgrove

你应该有$product 您可以拨打全球电话set_short_description 然后save 要存储更改,请执行以下操作:

$product->set_short_description(\'some description\');
$product->save();

相关推荐

使用较新的PHP版本时出现PHP错误

在我的网站上启用PHP版本7.2.17或更新版本时,我会在一些页面上收到与PHP相关的错误消息。Warning: 在中使用未定义的常量comment\\u notes\\u before-假定“comment\\u notes\\u before”(这将在PHP的未来版本中引发错误)/home/(username)/public_html/(domain name).com/wp-content/themes/Divi-child/comments.php 在线68下面是注释第68行的代码。php文件:c