在WooCommerce中,当我添加几行代码来更改产品描述时,在产品状态更改时,网站在提交时抛出一个错误(保存)。
我的代码:
add_action(\'transition_post_status\', \'new_product_add\', 10, 3);
function new_product_add($new_status, $old_status, $post) {
if(
$old_status != \'publish\'
&& $new_status == \'pending\'
&& !empty($post->ID)
&& in_array( $post->post_type,
array( \'product\')
)
) {
$term = get_term_by(\'name\', \'فروش پیج اینستاگرام\', \'product_cat\');
wp_set_object_terms($post->ID, $term->term_id, \'product_cat\', true);
/******************************/
$product = wc_get_product($post->ID);
$product->set_description("something");
$product->save();
/******************************/
}
}
如您所见,最后3行导致了问题页面刷新,也更新了产品描述,但给出了我和错误“THE SITE IS EXPERIENCING TECHNICAL DIFFICULTIES”
当我移除它们时,它可以正常工作,并向我显示成功的消息UPDATE
我用Wordpress的方式更改了这3行wp_update_post( array(\'ID\' => $post->ID, \'post_content\' => "something"));
仍然在做这项工作,但不是成功的消息给了我这个技术错误UPDATE II
当我打开Chrome控制台时,我也看到了这个错误Failed to load resource: the server responded with a status of 500 () (index):1