lập trình thay đổi hiển thị khuyến mãi trong woocommerce:

lập trình dưới đây giúp bạn chuyển đổi cách hiển thị giảm giá một cách cuốn hút người xem. Gây ấn tượng và đầy đủ thông tin rộng rãi mà khách hàng nên biết.

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
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
/*Sale price by devvn - levantoan.com*/
function devvn_price_html($product, $is_variation = false) $product->is_type('external')))
$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="devvn_single_price">
<div>
<span class="label">Giá:</span>
<span class="devvn_price"><?php echo wc_price($sale_price); ?></span>
</div>
<div>
<span class="label">Thị trường:</span>
<span class="devvn_price"><del><?php echo wc_price($regular_price); ?></del></span>
</div>
<div>
<span class="label">Tiết kiệm:</span>
<span class="devvn_price sale_amount"> <?php echo wc_price($sale_amout); ?> (<?php echo $sale; ?>%)</span>
</div>
</div>
<?php
elseif($product->is_on_sale() && $product->is_type('variable'))
$prices = $product->get_variation_prices( true );
if ( empty( $prices['price'] ) )
$price = apply_filters( 'woocommerce_variable_empty_price_html', '', $product );
else
$min_price = current( $prices['price'] );
$max_price = end( $prices['price'] );
$min_reg_price = current( $prices['regular_price'] );
$max_reg_price = end( $prices['regular_price'] );
if ( $min_price !== $max_price )
$price = wc_format_price_range( $min_price, $max_price ) . $product->get_price_suffix();
elseif ( $product->is_on_sale() && $min_reg_price === $max_reg_price )
$sale = round(((floatval($max_reg_price) - floatval($min_price)) / floatval($max_reg_price)) * 100);
$sale_amout = $max_reg_price - $min_price;
?>
<div class="devvn_single_price">
<div>
<span class="label">Giá:</span>
<span class="devvn_price"><?php echo wc_price($min_price); ?></span>
</div>
<div>
<span class="label">Thị trường:</span>
<span class="devvn_price"><del><?php echo wc_price($max_reg_price); ?></del></span>
</div>
<div>
<span class="label">Tiết kiệm:</span>
<span class="devvn_price sale_amount"> <?php echo wc_price($sale_amout); ?> (<?php echo $sale; ?>%)</span>
</div>
</div>
<?php
else
$price = wc_price( $min_price ) . $product->get_price_suffix();
echo $price;
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();
function woocommerce_template_single_price()
global $product;
echo devvn_price_html($product);
add_filter('woocommerce_available_variation','devvn_woocommerce_available_variation', 10, 3);
function devvn_woocommerce_available_variation($args, $thisC, $variation)
$old_price_html = $args['price_html'];
if($old_price_html)
$args['price_html'] = devvn_price_html($variation, true);
return $args;

khách hàng chỉ cần phải thêm đoạn lập trình sau vào functions.php của theme đang kích hoạt là được. Chú ý là code đã bao gồm css nếu không thích dạng này thì tự thay đổi lại.

Cách tùy chỉnh function.php để chuyển đổi style hiển thị của woocommerce trong Wp

Tùy chỉnh function.php trong Wp khá đơn giản và dễ dàng, bạn chỉ việc tìm kiếm file function.php của theme đang dùng và thêm code vào đó. Khuyến cáo: tốt nhất nên dùng Child theme để tinh chỉnh. Bạn vào Wp người quản lý -> Giao diện -> Sửa (giao diện) và tìm file function.php. Tùy Word press theme sẽ sở hữu các vị trí file function khác nhau. Thêm code tùy chỉnh vào sau thẻ <?php, cần để dưới sau cùng của file. function.php

Trước khi tùy biến, xin lưu ý: “backup website hoặc làm chạy thử trên local host, ít nhất cũng khắc ghi file function.php nguyên bản đã nhé. Đừng dại mà ném toẹt lập trình ngay vào web site chính!”

Kết quả: Tận hưởng kết quả thôi!

Xem các nội dung bài viết liên quan: https://sieutocviet.page/menu-widget-area/ https://sieutocviet.page/cai-https-cung-really-simple-ssl/ https://sieutocviet.page/ui-ux-la-gi/

3/5 - (2 bình chọn)

Hướng dẫn thay đổi code style hiển thị giảm giá woocommerce

Lê Trương Tấn Lộc (sieutocviet.net)

Trải qua 6 năm kinh nghiệm Python, PHP 5 năm kinh nghiệm trong quản lý website tư vấn giải pháp Seo google, Kinh doanh online tối ưu nhất cho doanh nghiệp.
Hiện làm leader kinh doanh tại Siêu Tốc Việt.