Remove the sale price of all products in WooCommerce admin

advertisements

Looking for a way to remove the sale price from all products in woocommerce. The admin has a limited view, so with a site that has over 10,000 products, removing the sale price manually can be a very tedious task.

Can this be done?


You can bulk edit the sale price on the products admin.

Or you could drop this into your functions.php temporarily.... load the admin once, and then remove after. (untested so use at your own risk)

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' );