Skip to content

Instantly share code, notes, and snippets.

@davidperezgar
Created April 16, 2019 08:54
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save davidperezgar/f8487829a9071a5020160c2563fb2ffc to your computer and use it in GitHub Desktop.
Save davidperezgar/f8487829a9071a5020160c2563fb2ffc to your computer and use it in GitHub Desktop.
WooCommerce rutine for update weights products
<?php
ini_set( 'memory_limit', '1024M' );
ini_set( 'max_execution_time', 600 );
define( 'WP_USE_THEMES', false );
require_once 'wp-load.php';
echo 'iniciado proceso.' . date( 'H:i:s', time() ) . '<br />';
$weight_final = '1000';
$posts_product = get_posts( 'posts_per_page=-1&post_type=product&fields=ids' );
if ( ! empty( $posts_product ) ) {
foreach ( $posts_product as $productID ) {
$product = wc_get_product( $productID );
$weight = get_post_meta( $productID, '_weight', true );
echo '---<br />';
echo 'PostID: ' . $productID . '<br/>';
echo 'Weight: ' . $weight . ' final:' . $weight_final . ' </br>';
if ( 0 == $weight ) {
update_post_meta( $productID, '_weight', $weight_final );
}
}
}
echo 'process finished.' . date( 'H:i:s', time() ) . '<br />';
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment