仅在woocommerce上应用功能(更新日期)

时间:2015-08-13 21:43:24

标签: php wordpress function woocommerce

有一种方法只能在woocommerce帖子类型上应用此功能吗?

function reset_post_date_wpse_121565($data,$postarr) {
// var_dump($data,$postarr); die; // debug
$data['post_date'] = $data['post_modified'];
$data['post_date_gmt'] = $data['post_modified_gmt'];
return $data;
}
add_filter('wp_insert_post_data','reset_post_date_wpse_121565',99,2);

我需要在更新后重置woocommerce产品。

1 个答案:

答案 0 :(得分:2)

对于wp_insert_post_data过滤器,只需将帖子类型与cpt进行比较。

function reset_post_date_wpse_121565($data,$postarr) {

   if($data['post_type'] !== 'product')
        return $data;

   $data['post_date'] = $data['post_modified'];
   $data['post_date_gmt'] = $data['post_modified_gmt'];
   return $data;
}
add_filter('wp_insert_post_data','reset_post_date_wpse_121565',99,2);