Created
April 16, 2019 08:54
-
-
Save davidperezgar/f8487829a9071a5020160c2563fb2ffc to your computer and use it in GitHub Desktop.
WooCommerce rutine for update weights 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 | |
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