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?
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' );
Step 1: Remove discount prices data:
DELETE FROM wp_postmeta WHERE meta_key IN ('_sale_price', '_sale_price_dates_to', '_sale_price_dates_from', '_price');
Step 2: Insert product price based on regular price
INSERT INTO wp_postmeta SELECT NULL, post_id, '_price', meta_value FROM wp_postmeta WHERE meta_key = '_regular_price';
Why DB queries?
In my case I have
SELECT COUNT(*) FROM marin2_postmeta WHERE meta_key = '_price';
+----------+
| COUNT(*) |
+----------+
| 10213 |
+----------+
1 row in set (0.03 sec)
You can completely remove sale badge from the product just past the below code in your function file.
remove_action( 'woocommerce_before_shop_loop_item_title', 'woocommerce_show_product_loop_sale_flash', 10 );