Thứ Hai, 19/05/2025
Loading...
  • Login
Hoàng Giang Nam Blog
  • Home
  • WordPress
    • WordPress
    • Woocommerce
  • Windows
  • Office
  • Phần Mềm
  • Thủ thuật
  • Linux
    • Ubuntu
    • CentOS
    • VPS – Server
    • Web Server
No Result
View All Result
Hoàng Giang Nam Blog
  • Home
  • WordPress
    • WordPress
    • Woocommerce
  • Windows
  • Office
  • Phần Mềm
  • Thủ thuật
  • Linux
    • Ubuntu
    • CentOS
    • VPS – Server
    • Web Server
No Result
View All Result
  • Login
Hoàng Giang Nam Blog
No Result
View All Result
Home Wordpress Woocommerce
Tăng / Giảm giá SALE toàn bộ cửa hàng, Xóa Giá Sale

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

admin by admin
01/01/2025
Share on FacebookShare on Twitter

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
// Sử dụng cho sản phẩm đơn giản và biến thể
add_filter('woocommerce_product_get_price', 'apply_storewide_discount', 99, 2);
add_filter('woocommerce_product_get_sale_price', 'apply_storewide_discount', 99, 2);
add_filter('woocommerce_product_variation_get_price', 'apply_storewide_discount', 99, 2);

function apply_storewide_discount($price, $product) {
    // Phần trăm giảm giá (ví dụ: 20%)
    $discount_percentage = 20;

    // Tính giá sau khi giảm
    $discount_factor = 1 - ($discount_percentage / 100);
    $price = $product->get_regular_price() * $discount_factor;

    return $price; // Trả về giá đã giảm
}

 

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 trên toàn bộ cửa hàng
// =========================
function disable_all_sales($price, $product) {
    // Trả về giá gốc (regular price) thay vì giá sale
    return $product->get_regular_price();
}

// Áp dụng xóa giá sales
add_filter('woocommerce_product_get_sale_price', 'disable_all_sales', 50, 2);
add_filter('woocommerce_product_get_price', 'disable_all_sales', 50, 2);
add_filter('woocommerce_product_variation_get_price', 'disable_all_sales', 50, 2); // Áp dụng cho sản phẩm biến thể

 

Tags: Woocommerce
admin

admin

Next Post
Code tự động tải lại trang – Auto REFRESH Page WordPress

Code tự động tải lại trang - Auto REFRESH Page Wordpress

Please login to join discussion

Recommended.

Hướng Dẫn Thêm IPv4 và Cấu Hình tại VPS OVH – Centos 8

Hướng Dẫn Thêm IPv4 và Cấu Hình tại VPS OVH – Centos 8

19/12/2024
Cách ẩn logo reCAPTCHA Google

Cách ẩn logo reCAPTCHA Google

18/12/2024

Trending.

HuananZhi X79 / X99 Motherboard BIOS POST codes

HuananZhi X79 / X99 Motherboard BIOS POST codes

01/01/2025
Xóa, Sửa, Nâng dung lượng RAM ẢO – Swap trên Ubuntu

Xóa, Sửa, Nâng dung lượng RAM ẢO – Swap trên Ubuntu

01/01/2025
Tạo file IMG Windows.GZ bằng VM VirtualBox để cài đặt trên VPS Digitalocean, Linode

Tạo file IMG Windows.GZ bằng VM VirtualBox để cài đặt trên VPS Digitalocean, Linode

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

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

01/01/2025

GG One 1năm

18/12/2024
Hoàng Giang Nam

Blog chia sẽ kiến thức lập trình, source code, themes, plugin, phần mềm & thủ thuật máy tính...

Follow Us

Danh mục

  • CentOS
  • Chung
  • Server Email
  • Thủ thuật máy tính
  • Ubuntu
  • VPS – Server
  • Web Server
  • Windows
  • Woocommerce
  • Wordpress

Recent News

Disable Web Search Results in Windows 10/11 Start Menu

16/01/2025
Hướng dẫn lấy Client ID + Client Secret + Refresh Token Google Drive API

Hướng dẫn lấy Client ID + Client Secret + Refresh Token Google Drive API

19/12/2024
  • About
  • Advertise
  • Privacy & Policy
  • Contact

© 2024 Hoanggiangnam.com

No Result
View All Result
  • Home
  • Phần Mềm
  • Thủ thuật máy tính
  • WordPress
  • Ubuntu
  • Office
  • Photography
  • Windows

© 2024 Hoanggiangnam.com

Welcome Back!

Login to your account below

Forgotten Password?

Retrieve your password

Please enter your username or email address to reset your password.

Log In
Click to Copy