Hướng dẫn thêm nút Mua ngay sau nút Thêm vào giỏ hàng
Mở file functions.php
trong child theme của bạn (nếu chưa có child theme, bạn nên tạo child theme để tránh mất thay đổi khi update theme). Thêm đoạn code sau:
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 |
//mua nhanh add_action('woocommerce_after_add_to_cart_button','webdy_quickbuy_after_addtocart_button'); function webdy_quickbuy_after_addtocart_button(){ global $product; ?> <style> .webdy-quickbuy button.single_add_to_cart_button.loading:after { display: none; } .webdy-quickbuy button.single_add_to_cart_button.button.alt.loading { color: #fff; pointer-events: none !important; } .webdy-quickbuy button.buy_now_button { position: relative; color: rgba(255,255,255,0.05); } .webdy-quickbuy button.buy_now_button:after { animation: spin 500ms infinite linear; border: 2px solid #fff; border-radius: 32px; border-right-color: transparent !important; border-top-color: transparent !important; content: ""; display: block; height: 16px; top: 50%; margin-top: -8px; left: 50%; margin-left: -8px; position: absolute; width: 16px; } button.button.buy_now_button{ background: #0d986f; border-radius: 4px; text-transform: none; } </style> <button type="button" class="button buy_now_button"> <?php _e('<i class="fa fa-credit-card" aria-hidden="true"></i> Thanh toán ngay', 'webdy'); ?> </button> <input type="hidden" name="is_buy_now" class="is_buy_now" value="0" autocomplete="off"/> <script> jQuery(document).ready(function(){ jQuery('body').on('click', '.buy_now_button', function(e){ e.preventDefault(); var thisParent = jQuery(this).parents('form.cart'); if(jQuery('.single_add_to_cart_button', thisParent).hasClass('disabled')) { jQuery('.single_add_to_cart_button', thisParent).trigger('click'); return false; } thisParent.addClass('webdy-quickbuy'); jQuery('.is_buy_now', thisParent).val('1'); jQuery('.single_add_to_cart_button', thisParent).trigger('click'); }); }); </script> <?php } add_filter('woocommerce_add_to_cart_redirect', function($url) { if(isset($_POST['is_buy_now']) && $_POST['is_buy_now'] == '1') { return wc_get_checkout_url(); // Chuyển đến trang thanh toán } return $url; }); |
Quý khách cần tư vấn thiết kế web giá rẻ, vui lòng nhấn nút bên dưới:
Chào ! Bạn thấy nội dung này thế nào?
Xem thêm: