【发布时间】:2020-02-12 04:40:12
【问题描述】:
每当发布新产品(要发布的草稿)时,我都会尝试添加 woocommerce 销售日期。
我的所有代码都根据我的评论运行,所有变量都可以正常显示,没有错误,但是当我检查帖子元数据和管理员时,没有添加任何日期。 get_post_meta 中没有任何内容,产品编辑屏幕中也没有任何内容。
add_action('transition_post_status', array($this, 'knp_add_sale_date'), 20, 3);
public function knp_add_sale_date($new, $old, $post){
$meta = get_post_meta($post->ID);
$submissiondata = $this->get_submission($meta['submissionID'][0]);
$submissiondata['live_status'] = $new;
//If the post is a new product published from draft.
if ($old == 'draft' && $new == 'publish' && $post->post_type == 'product') {
//If there is a sale on then set the sale dates
if (isset($meta['_sale_price'][0])) {
$startdatedate = new DateTime('now');
$startdateformat = $startdatedate->format('Y-m-d');
$enddate = date('Y-m-d', strtotime($startdateformat. ' + 15 days'));
$finishdate = new DateTime($enddate);
//Everything works till here
update_post_meta($post->ID, '_sale_price_dates_from', $startdatedate->getTimestamp());
update_post_meta($post->ID, '_sale_price_dates_to', $finishdate->getTimestamp());
}
$update = $this->post_submission($submissiondata, $meta['submissionID'][0], 'live');
}
}
TIA 寻求任何建议或帮助。
【问题讨论】: