按时间和特殊类别A删除WooCommerce产品

时间:2018-09-02 14:10:29

标签: php wordpress woocommerce product

我将代码添加到functions.php并可以很好地工作,但是我只需要删除一个特殊类别(而不是1个),但不能删除所有类别,只有3个WooCommerce产品类别需要运行此代码。如何仅搜索选定类别以删除??

function set_delete_product_meta($id) {
global $wpdb,$current_user;
$posttype = get_post_type($id);
if ( $posttype =='revision' )
   return;
   if($posttype=='product')
   {
    $val=get_post_meta( $id, 'wdm_set_expiry',true);
         if($val!=1)
         {
            $month     = date('m');
            $day      = date('d')+X;
            $year      = date('Y');
            $hour      = date('H');
            $minute  =date('i');        
            $dt = get_gmt_from_date("$year-$month-$day $hour:$minute:0",'U');
            $vars = $id;
            wdm_delete_product($dt,$id,$vars);
            update_post_meta($id,'wdm_set_expiry',1);
         }
}
else
return;
}
add_action('wp_insert_post','set_delete_product_meta');



function wdm_delete_product($remove_date,$id,$vars) {
    if (wp_next_scheduled('wdm_remove_product',array($id)) !== false) 
        wp_clear_scheduled_hook('wdm_remove_product',array($id));
        wp_schedule_single_event($ts,'wdm_remove_product',array($id));
        // Update Post Meta
        update_post_meta($id, 'wdm_product_remove_date', $remove_date);
        update_post_meta($id, 'wdm_product_remove_date-value', $vars);
}


function wdm_remove_product($id){
         global $wpdb;
         if (empty($id)){ 
            return false;
         }
         if (is_null(get_post($id))){
            return false;
         }
         $pr_value = get_post_meta($id,'wdm_product_remove_date-value',true);
     // wp_delete_post($pr_value) ; //This will delete product
     $wpdb->query("Update $wpdb->posts set post_status='draft' where ID='$id'");// Change status to draft
    }
    add_action('wdm_remove_product','wdm_remove_product');

0 个答案:

没有答案