Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
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
You can’t perform that action at this time.