根据月份更改WooCommerce产品状态(草稿->发布//发布->草稿)

时间:2018-08-11 作者:Lust

我有一些季节性产品。我想使用“post expirator插件”,但这并没有管理“Annual”选项。所以我想这样做:

function saison(){

 $current_month = date(\'M\');
    if(  $current_month == \'Dec\' || $current_month == \'Jan\' ) {
       wp_update_post( array( 
         \'ID\' => 789,
         \'post_status\' => \'publish\'
      ));
    } else {
        wp_update_post( array( 
         \'ID\' => 789,
         \'post_status\' => \'draft\'
      ));
    }
}

有人知道如何在我的函数中生成这样的东西。php?

1 个回复
SO网友:Ash0ur

日期(\'M\')=>\'Aug\'和日期(\'M\')=>08

add_action(\'wp\', function(){
    $current_month = date(\'M\');
    if( $current_month == \'Aug\' ) {
       wp_update_post( array( 
         \'ID\' => "product_id",
         \'post_status\' => \'publish\'
      ));
    } else {
        wp_update_post( array( 
         \'ID\' => "product_id",
         \'post_status\' => \'draft\'
      ));
    }
});

结束

相关推荐