Tăng / Giảm giá SALE toàn bộ cửa hàng, Xóa Giá Sale

1. Xóa giảm giá
Nếu cửa hàng (web shop) của bạn quá nhiều sản phẩm cà bạn không muốn xóa thủ công. Bạn muốn xóa toàn bộ Sale price và chỉ dùng Regular price thì bạn có thể sử dụng lệnh dưới để xóa và update lại database ở cột _price

DELETE FROM wp_postmeta WHERE meta_key = '_sale_price';
DELETE FROM wp_postmeta WHERE meta_key = '_sale_price_dates_to';
DELETE FROM wp_postmeta WHERE meta_key = '_sale_price_dates_from';

# mysql
# SHOW DATABASES;
# USE ten_database;

UPDATE wp_postmeta AS s LEFT JOIN wp_postmeta AS r ON s.post_id = r.post_id SET s.meta_value = r.meta_value WHERE s.meta_key = '_price' AND r.meta_key = '_regular_price'; then DELETE FROM wp_postmeta WHERE meta_key = '_sale_price';

2. Tăng / Giảm giá SALE toàn bộ cửa hàng
với giá bán thông qua woocommerce_get_sale_price bộ lọc.

Sao chép đoạn code này vào function.php của theme nhá:

// code giảm giá % toàn cửa hàng từ giá gốc// add_filter( 'woocommerce_product_variation_get_price', 'my_custom_price', 99, 2 ); // dòng này cho sp biến thể (nếu có thì bật lên nhá)add_filter( 'woocommerce_product_get_price', 'my_custom_price', 99, 2 );add_filter( 'woocommerce_product_get_sale_price', 'my_custom_price', 99, 2 );// add_filter('woocommerce_get_sale_price', 'my_custom_price', 99, 2); // WOO 3.0 đổ lại// add_filter('woocommerce_get_price', 'my_custom_price', 99, 2); // WOO 3.0 đổ lạifunction my_custom_price( $price, $product ){//your logic for calculating the new price here$price = $product->get_regular_price() * 0.8; // thay vào số phù hợp: 0.8 = 20% | 0.4 = 60%//Return the new price (this is the price that will be used everywhere in the store)return $price;}// end code giảm giá %

 

Chú ý giá trị: * 0.8 = Giảm 20% đó nhá. Cứ thử lấy 100 x 0.8 = 80 => giảm 20%

3. Hoặc bạn có thể xóa toàn bộ giá SALE tạm thời
bằng đoạn code sau vào functions.php:

//==================================================xóa giá sales/*** Disable all sales.** A simple function to disable all the sales in the shop.* Uncomment the line of code to disable the sale price on products.*/function custom_wc_get_sale_price( $sale_price, $product ) {return $product->get_regular_price(); // Un-comment this to disable all sale pricesreturn $sale_price;}add_filter( 'woocommerce_product_get_sale_price', 'custom_wc_get_sale_price', 50, 2 );add_filter( 'woocommerce_product_get_price', 'custom_wc_get_sale_price', 50, 2 );

Để lại một bình luận

Lên đầu trang