Como puedo borrar todas los precios en oferta de woocommerce

0 votos
preguntado por Zeus (16,780 puntos)

Tengo diez mil productos y quiero borrar todos  los precios de los productos que tengo en oferta 

function so_28048702_update(){
    // in theory this will grab all variations FIRST
    $args = array( 'post_type' => array( 'product','product-variation' ), 'nopaging' => true, 'sortby' => 'post_type', 'order' => 'desc' );

    $all_products = new WP_Query( $args );

    if ( $all_products->have_posts() ) : 
    while ( $all_products->have_posts() ) : 

        $all_products->the_post();
        $id = get_the_ID();
        update_post_meta( $id, '_sale_price', '' );
        $regular_price = get_post_meta( $id, '_regular_price', true );
        update_post_meta( $id, '_price', $regular_price );

        // we're on a variable product
        if( has_term( 'variable', 'product_type', $id ) ){
           variable_product_sync( $id );
        }

    endwhile;
    endif;

    wp_reset_postdata();

}
add_action( 'admin_init', 'so_28048702_update' );

1 Respuesta

0 votos
respondido por Zeus (16,780 puntos)
 
Mejor respuesta
ya está, me respondo yo mismo. copio pego
Bienvenido a Preguntas y respuestas para programadores o profesionales de la informática. Si tienes cualquier duda aquí obtendrás la respuesta.
...