Các tùy chỉnh về giá này giúp bạn dễ dàng điều chỉnh sản phẩm sao cho phù hợp với đối tượng khách hàng và chính sách bán hàng của doanh nghiệp. Tunlamweb sẽ hướng dẫn bạn nhiều tính năng tùy chỉnh về giá linh hoạt để phù hợp với các nhu cầu kinh doanh khác nhau. Dưới đây là các tùy chỉnh phổ biến nhất về giá trong
Cấu hình giá theo thuế
Phần này mình sẽ hướng dẫn bạn Custom giá khi có Thuế

Add code file functions.php
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 | /* * Custom Giá theo giá thuế * Author: https://tunlamweb.com/ */ function tunlw_price_html($product, $is_variation = false){ ob_start(); if($product->get_price() > 0 ) { $regular_price = $product->get_regular_price(); if($regular_price) { $price_gtgt = round(((floatval($regular_price) / 1.08))); //(Thuế 8% = 1.08 - Thuế 10% = 1.1) ?> <div class="tunlw_single_price"> <div> <span class="label">Giá bao gồm thuế GTGT:</span> <span class="tunlw_price"><?php echo wc_price($regular_price); ?></span> </div> <div class="price-sale"> <div> <span class="label">Thuế GTGT:</span> <span class="tunlw_price">8%</span> </div> <div> <span class="label">Giá chưa bao gồm thuế GTGT:</span> <span class="tunlw_price sale_amount"><?php echo wc_price($price_gtgt); ?></span> </div> </div> </div> <?php } }else{ ?> <p class="<?php echo esc_attr( apply_filters( 'woocommerce_product_price_class', 'price' ) );?>"><?php echo $product->get_price_html(); ?></p> <?php } return ob_get_clean(); ?> <!-- Custom CSS --> <style type="text/css"> .tunlw_single_price { margin-bottom: 10px; } .tunlw_single_price span.tunlw_price,.tunlw_single_price span.tunlw_price span{ color: red; font-weight: 600; } p.price .amount { color: red; font-weight: 600; } </style> <?php } function woocommerce_template_single_price(){ global $product; echo tunlw_price_html($product); } |
Cấu hình giá theo giá khuyến mãi
Phần này mình sẽ hướng dẫn bạn Custom giá khi có Thuế

Add code file functions.php
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 | /* Giá theo giá khuyến mãi*/ function tunlw_price_html($product, $is_variation = false){ ob_start(); if($product->is_on_sale() && ($product->is_type( 'simple' ) || $product->is_type( 'external' ) || $is_variation) ) { $sale_price = $product->get_sale_price(); $regular_price = $product->get_regular_price(); if($regular_price) { $sale = round(((floatval($regular_price) - floatval($sale_price)) / floatval($regular_price)) * 100); $sale_amout = $regular_price - $sale_price; ?> <div class="tunlw_single_price"> <div> <span class="label">Giá thị trường:</span> <span class="tunlw_price"><del><?php echo wc_price($regular_price); ?></del></span> </div> <div class="price-sale"> <div> <span class="label">Giá ưu đãi:</span> <span class="tunlw_price"><?php echo wc_price($sale_price); ?> (Giá chưa gồm VAT)</span> </div> <div> <span class="label">Tiết kiệm:</span> <span class="tunlw_price sale_amount"> <?php echo wc_price($sale_amout); ?> (<?php echo $sale; ?>%)</span> </div> </div> </div> <?php } }else{ ?> <p class="<?php echo esc_attr( apply_filters( 'woocommerce_product_price_class', 'price' ) );?>"><?php echo $product->get_price_html(); ?></p> <?php } return ob_get_clean(); ?> <!-- Custom CSS --> <style type="text/css"> .price-sale .sale_amount,.price-sale .sale_amount bdi, .tunlw_single_price .price-sale span.amount{ font-size: 16px; color: red; } </style> <?php } function woocommerce_template_single_price(){ global $product; echo tunlw_price_html($product); } |
Cấu hình giá liên hệ – khi 0đ và không nhập giá
Add code file functions.php
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 | /* * Chuyển 0đ thành chữ “Liên hệ” trong woocommerce * Author: https://tunlamweb.com/ */ function tunlw_ct_custom_price_html( $price, $product ) { if ( ! $product->get_price() ) { if ( $product->is_on_sale() && $product->get_regular_price() ) { $regular_price = wc_get_price_to_display( $product, array( 'qty' => 1, 'price' => $product->get_regular_price() ) ); $price = wc_format_price_range( $regular_price, __( 'Liên hệ', 'woocommerce' ) ); } else { $price = '<span class="amount">' . __( 'Liên hệ', 'woocommerce' ) . '</span>'; } } return $price; } add_filter( 'woocommerce_get_price_html', 'tunlw_ct_custom_price_html', 10, 2 ); function tunlw_custom_price_html( $price, $product ) { if ( !is_admin() && !$product->is_in_stock()) { $price = '<span class="amount">' . __( 'Liên hệ', 'woocommerce' ) . '</span>'; } return $price; } add_filter( 'woocommerce_get_price_html', 'tunlw_custom_price_html', 99, 2 ); |
Plugin hỗ trợ tùy chỉnh giá
Có nhiều plugin hữu ích hỗ trợ nâng cao tính năng về giá sản phẩm trong WooCommerce như:
- WooCommerce Dynamic Pricing & Discounts
- WooCommerce Price Based on Country (giá theo khu vực)
- WooCommerce Subscriptions (cho phép định giá theo gói đăng ký)
