• Bỏ qua primary navigation
  • Skip to main content
  • Bỏ qua primary sidebar

Thủ thuật thiết kế website

Chia sẻ kinh nghiệm thiết kế website

  • Trang chủ
  • Joomla
    • Thủ thuật Joomla
    • Joomla Extensions
    • Joomla Themes
  • WordPress
    • Thủ thuật WordPress
    • WordPress Plugins
    • WordPress Themes
  • Web Development
    • HTML/CSS
    • Javascript
    • PHP
  • PHP Framework
    • Codeigniter
    • Laravel
    • Laminas
  • App Developer
    • React Native
    • Flutter
  • SEO
  • Chia sẻ
  • Phần mềm
Bạn đang ở:Trang chủ / Wordpress / Thủ thuật WordPress / Hướng dẫn thêm trạng thái sản phẩm trong Woocommerce

Hướng dẫn thêm trạng thái sản phẩm trong Woocommerce

29/12/2021 - Administrator 2 Bình luận

Mặc định, woo chỉ có các trạng thái còn hàng, chờ hàng, hết hàng. Nay muốn thêm các trang thái khác như backorder, ngừng kinh doanh, các bạn làm như sau.

Chép toàn bộ code dưới đây vào function.php của theme. Css lại cho đẹp nếu cần.
// Add new stock status options
function filter_woocommerce_product_stock_status_options($status)
{
    // Add new statuses
    $status['sob_product'] = __('Ngừng kinh doanh', 'woocommerce');
    $status['contact_us'] = __('Liên hệ', 'woocommerce');
    return $status;
}
add_filter('woocommerce_product_stock_status_options', 'filter_woocommerce_product_stock_status_options', 10, 1);

// Availability text
function filter_woocommerce_get_availability_text($availability, $product)
{
    // Get stock status
    switch ($product->get_stock_status()) {
        case 'sob_product':
            $availability = __('Ngừng kinh doanh', 'woocommerce');
            break;
        case 'contact_us':
            $availability = __('Liên hệ', 'woocommerce');
            break;
    }
    return $availability;
}
add_filter('woocommerce_get_availability_text', 'filter_woocommerce_get_availability_text', 10, 2);

// Availability CSS class
function filter_woocommerce_get_availability_class($class, $product)
{
    // Get stock status
    switch ($product->get_stock_status()) {
        case 'sob_product':
            $class = 'sob-product';
            break;
        case 'contact_us':
            $class = 'contact-us';
            break;
    }
    return $class;
}
add_filter('woocommerce_get_availability_class', 'filter_woocommerce_get_availability_class', 10, 2);
// An example based on global $product
// Get the global product object
global $product;
// Is a WC product
if (is_a($product, 'WC_Product')) {
    // Get stock status
    $product_stock_status = $product->get_stock_status();
    // Compare
    if ($product_stock_status == 'My custom stock status') {
        // Etc..
    }
}

Nguồn : WordPress VietCoders Community

0 0 đánh giá
Article Rating
Theo dõi
Đăng nhập
Thông báo của
guest
guest
2 Comments
Cũ nhất
Mới nhất Được bỏ phiếu nhiều nhất
Phản hồi nội tuyến
Xem tất cả bình luận
trường
trường
26 ngày trước

Mình chèn vào mà sao ko không thấy hiện ngừng kinh doanh nhỉ

0
Trả lời
Administrator
Tác giả
Administrator
15 ngày trước
Trả lời  trường

Chào bạn, bạn thêm xong thì vào admin sản phẩm chọn mục lại nha ! Cám ơn bạn

0
Trả lời

Sidebar chính

LỜI NGỎ

Đây là blog cá nhân, cung cấp các thông tin, kiến thức và kinh nghiệm về lập trình và cuộc sống. Những bài viết được mình sưu tập từ nhiều nguồn, mọi chi tiết liên quan đến bản quyền xin vui lòng liên hệ qua email kairu2607@gmail.com ! Cám ơn rất nhiều.

Tìm kiếm

Thủ thuật Wordpress

Vì Sao Rank Math Vượt Trội – SEO WordPress 2023

Thêm lượt xem bài viết vào WordPress Post Views Counter

Website Bị Hack Virus Index Tiếng Nhật và Toàn Tập Các Cách Xử Lý

Hướng dẫn tạo liên hệ All in one phiên bản có yêu cầu gọi lại

Tạo gợn sóng phân cách bằng SVG trên Flatsome

Tự động đăng nhập WordPress

Hướng Dẫn Upload Plugin Lên WordPress.org

Codeigniter Framework

[CodeIgniter 4] Codeigniter 4 Remove Public and Index.php From URL

[CodeIgniter 4] How to upload Codeigniter 4 website on share hosting?

Sửa lỗi website Codeigniter 2.x không chạy được với PHP 7.x

[CodeIgniter 4] Sử dụng cURL trong CodeIgniter 4

[CodeIgniter 4] Sử dụng cache để tăng tốc website trong CodeIgniter 4

[CodeIgniter 4] Xử lý hình ảnh chuyên nghiệp trong CodeIgniter 4

[CodeIgniter 4] Hướng dẫn gửi mail trong CodeIgniter 4

Dịch vụ Thiết Kế Website

Laravel

Laravel Cũng Có Notifications?

Cách Bảo Mật Đơn Giản Trong Laravel Bằng Ẩn Config Quan Trọng

Tạo Desktop Notification đơn giản và dể hiểu

Vime thư viện HTML5 Player vừa đẹp mà vừa ngon

Laravel domPDF cách tùy biến Font chữ bất chấp mọi thể loại

Laravel JetStream

Phần mềm hay

Hướng dẫn tắt Gatekeeper (Bật tùy chọn Anywhere) sửa lỗi “damaged and can’t be opened. You should move it to the Trash”

Cài lại macOS trên Mac Silicon (M1) “sạch trơn” bằng macOS Recovery

Cách vào Recovery [Startup Options] trên Mac dùng chip Apple Silicon [M1]

Hướng dẫn tắt System Integrity Protection (SIP) để chạy App Cr4ck

Remote System Explorer (SSH, Telnet, FTP and DStore protocols)

Copyright © 2023 · Metro Pro on Genesis Framework · WordPress · Đăng nhập

wpDiscuz