Skip to content

Instantly share code, notes, and snippets.

@forsvunnet
Created November 4, 2017 21:06
Show Gist options
  • Save forsvunnet/d1bf2bc750af45c476b01038122dd9bc to your computer and use it in GitHub Desktop.
Save forsvunnet/d1bf2bc750af45c476b01038122dd9bc to your computer and use it in GitHub Desktop.
Zero dimensions
<?php
$wp_did_header = true;
require_once 'public/wp-load.php';
$args = [
'post_type' => 'product',
'posts_per_page' => -1,
'fields' => 'ids',
];
$posts = get_posts( $args );
$count = 0;
foreach ( $posts as $post_id ) {
$product = wc_get_product( $post_id );
// var_dump( get_class_methods( $product ) );
$dims =
$product->get_width()+
$product->get_height()+
$product->get_length();
if ( $dims ) {
echo $product->get_name();
echo "\n";
$product->set_width( 0 );
$product->set_height( 0 );
$product->set_length( 0 );
$product->save();
$count++;
}
}
echo "Total: $count\n";
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment