Cập nhật trạng thái giỏ hàng mini ngay tức thì
Có nghĩa là khi khách hàng click vào nút add to cart thì ngay lập tức số lượng và tổng giá trị đơn hàng được hiển thị trên giỏ hàng mini mà không cần refresh trang
Code làm việt này:
Khi khách hàng click add to cart thì anh chị thấy rằng có xuất hiện một icon quay tròn, để chỉ trạng thái sản phẩm được đang được thêm vào, tuy nhiên khi ngoài trang chủ class woocommerce không được add vào thẻ body nên chúng ta sẽ không thấy điều đó, bây giờ chúng ta phải đi add nó vào
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
|
<?php
class products_featured extends WP_Widget
{
function products_featured(){
$widget_ops = array('description' => 'Products featured');
$control_ops = array('width' => 300, 'height' => 300);
parent::WP_Widget(false,$name='Products featured',$widget_ops,$control_ops);
}
function form($instance){
global $wpdb;
//Defaults
$instance = wp_parse_args( (array) $instance, array('title'=>'','numbershow'=>'') );
$title = htmlspecialchars($instance['title']);
$numbershow = htmlspecialchars($instance['numbershow']);
?>
<p><label for="<?php echo $this->get_field_id('title'); ?>">Title </label>
<input type="text" name="<?php echo $this->get_field_name('title'); ?>" id="<?php echo $this->get_field_id('title'); ?>" style="width:100%" value="<?php echo $title; ?>">
</p>
<p><label for="<?php echo $this->get_field_id('numbershow'); ?>">Show number: </label>
<input type="text" name="<?php echo $this->get_field_name('numbershow'); ?>" id="<?php echo $this->get_field_id('numbershow'); ?>" style="width:100%" value="<?php echo $numbershow; ?>">
</p>
<?php
}
/*Saves the settings. */
function update($new_instance, $old_instance){
$instance = $old_instance;
$instance['title'] = stripslashes($new_instance['title']);
$instance['numbershow'] = stripslashes($new_instance['numbershow']);
return $instance;
}
function widget($args, $instance) {
global $wpdb,$post, $product;
extract($args);
$title= empty($instance['title']) ? '' : $instance['title'];
$numbershow= empty($instance['numbershow']) ? '' : $instance['numbershow'];
echo $before_widget;
if ( ! empty( $instance['title'] ) ) {
echo $args['before_title'] . apply_filters( 'widget_title', $instance['title'] ). $args['after_title'];
}
?>
<div class="lastest-product-list">
<?php
$args = array(
'post_type' => 'product',
'meta_key' => '_featured',
'meta_value' => 'yes',
'meta_compare' => '=',
'posts_per_page' => $numbershow,
'post_status' => 'publish'
);
$wp_query = new WP_Query( $args );
if ( $wp_query->have_posts() ) : while ( $wp_query->have_posts() ) : $wp_query->the_post();
?>
<div class="cutom-woocommerce-product-item">
<div class="cutom-woocommerce-product-item-featured-image">
<a href="<?php the_permalink(); ?>" title="<?php the_title(); ?>">
<?php echo get_the_post_thumbnail(get_the_ID(), 'cumtom-featured-image-for-shop' ); ?>
</a>
</div>
<div class="cutom-woocommerce-product-item-title-and-price">
<h2><a href="<?php the_permalink(); ?>" title="<?php the_title(); ?>"><?php the_title(); ?></a></h2>
<p><?php woocommerce_get_template( 'loop/price.php' ); ?></p>
<?php
$product = wc_get_product( get_the_ID() );
$add_to_cart_link = sprintf( '<a href="%s" rel="nofollow" data-product_id="%s" class=" add_to_cart_button single_add_to_cart_button button product_type_%s">%s</a>',
esc_url( $product->add_to_cart_url() ),
$product->id,
esc_attr( $product->product_type ),
'Mua ngay'
);
echo $add_to_cart_link;
?>
</div>
</div>
<?php
endwhile;
wp_reset_postdata();
endif;
?> </div>
<?php
echo $after_widget;
?>
<?php
}
}// end class
register_widget('products_featured');
?>
|
0 nhận xét: