Skip to content

Instantly share code, notes, and snippets.

@alamgircsebd
Last active January 4, 2023 04:29
Show Gist options
  • Save alamgircsebd/12ce28e23ec5c87fa24e5814495ae53f to your computer and use it in GitHub Desktop.
Save alamgircsebd/12ce28e23ec5c87fa24e5814495ae53f to your computer and use it in GitHub Desktop.
Scripts for Delete WooCommerce Products by User ID
<?php
$userID = 2;
$args = array( 'author' => $userID, 'post_type' => 'product', 'posts_per_page' => -1, 'post_status' => array( 'publish', 'pending', 'draft', 'future' ) );
$the_query = new WP_Query( $args );
// The Loop
if ( $the_query->have_posts() ) {
while ( $the_query->have_posts() ) {
$the_query->the_post();
wp_delete_post( get_the_ID(), true );
echo '<ul>';
echo '<li>Deleted product ID: ' . get_the_ID() . '</li>';
echo '</ul>';
}
/* Restore original Post Data */
wp_reset_postdata();
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment