Rutina para actualizar los pesos de la tienda WooCommerce

Esta rutina detecta los productos que tengan como peso 0, y les añade un valor por defecto. Crea un archivo php en el raíz de tu instalación WordPress, con la información a continuación, y personaliza el valor del peso $weight_final para los productos, en la linea 9.

wc peso woocommerce
<?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 />';

Recuerda siempre hacer una copia de seguridad de tu instalación WordPress, antes de hacer cualquier cambio.

4 thoughts on “Rutina para actualizar los pesos de la tienda WooCommerce”

Mentions

  • David Pérez
  • Ruben
  • David Pérez
  • Ruben

Leave a Comment

ÚLTIMOS ARTÍCULOS

Cierre Ventana

My Second Year on the WordPress Plugin Review Team

And yes, I've been contributing to WordPress in the Plugins team for two years now. For those who…

Cierre Ventana

State of the Word: Plugins

Photo taken by wordpress.org Yesterday, the new features that WordPress will be working on in the coming year…

Cierre Ventana

New version of Plugin Check Plugin 1.3.0

A new version of Plugin Check Plugin has been released. Version 1.3.0 brings enhancements, including new checks for…

Logo David
Privacy Resume

Esta web utiliza cookies para que podamos ofrecerte la mejor experiencia de usuario posible. La información de las cookies se almacena en tu navegador y realiza funciones tales como reconocerte cuando vuelves a nuestra web o ayudar a nuestro equipo a comprender qué secciones de la web encuentras más interesantes y útiles.Para más información consulta nuestra <a href="/politica-privacidad/">Política de Privacidad</a>