Created
March 24, 2020 14:28
-
-
Save mustardBees/463bc5baa38aeb49cf44e709b75d7e04 to your computer and use it in GitHub Desktop.
Generate list of WooCommerce variable products.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/* | |
Plugin Name: List Variable Products | |
Plugin URI: https://www.philwylie.co.uk/ | |
Description: Generate list of WooCommerce variable products. | |
Version: 1.0.0 | |
Author: Phil Wylie | |
Author URI: https://www.philwylie.co.uk/ | |
License: GPL2 | |
*/ | |
/** | |
* Class PW_List_Variable_Products. | |
*/ | |
class PW_List_Variable_Products { | |
/** | |
* Initialize the plugin by hooking into WordPress. | |
*/ | |
public function __construct() { | |
add_action( 'init', array( $this, 'generate_list' ) ); | |
} | |
/** | |
* Hit example.com/?export-products. Use at your own risk. Backup first! | |
*/ | |
public function generate_list() { | |
if ( ! isset( $_GET['export-products'] ) ) { | |
return; | |
} | |
$args = array( | |
'posts_per_page' => '-1', | |
'post_type' => 'product', | |
'tax_query' => array( | |
array( | |
'taxonomy' => 'product_type', | |
'field' => 'slug', | |
'terms' => 'variable', | |
), | |
), | |
'no_found_rows' => true, | |
'cache_results' => false, | |
); | |
$posts = new WP_Query( $args ); | |
if ( $posts->have_posts() ) { | |
foreach ( $posts->posts as $post ) { | |
echo get_permalink( $post->ID ) . "\n"; | |
} | |
} | |
echo 'Done.'; | |
exit; | |
} | |
} | |
new PW_List_Variable_Products(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment