Thêm nút add to cart và mua ngay hiện khi scroll xuống dưới cho flatsome: Kết quả của chúng ta sẽ như hình bên dưới. Tất nhiên bạn phải sửa màu sắc và size các button cho phù hợp với site của bạn
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 |
function add_to_cart_mobile(){ if(is_product()): ?> <div class="add_to_cart_mobile"> <button type="button" id="add_to_cart_mobile" class="single_add_to_cart_button button alt custom"><i class="fa fa-cart-plus" aria-hidden="true"></i>Thêm vào giỏ hàng</button> <a class="button alt buy-now" href="#handle_buy_now">Mua ngay</a> </div> <script> jQuery(function($){ $(document).ready(function(e) { $(window).scroll(function() { if($(window).width() < 549){ if($(window).scrollTop() + $(window).height() > $(document).height() - 100) { $('.add_to_cart_mobile').show(); } } }); $(document).on('click', '#add_to_cart_mobile', function (e) { e.preventDefault(); $(this).addClass('loading'); $('.single_add_to_cart_button').trigger('click'); alert('Đã thêm vào giỏ hàng!'); }); }); }); </script> <?php endif; } add_action("flatsome_footer","add_to_cart_mobile"); |
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 |
.add_to_cart_mobile { position: absolute; bottom: 0; z-index: 999999999999; /* display: flex; */ width: 100%; display: none; } .add_to_cart_mobile button#add_to_cart_mobile { width: 50%; margin: 0 !important; border: none; line-height: 36px; background: #ddd; font-size: 14px; color: #ee4e2e; text-transform: capitalize; font-weight: 400; position: relative; display: inline-block; } .add_to_cart_mobile a.button.alt.buy-now { width: 50%; font-size: 14px; margin-right: 0; float: right; } |
tham khảo cách hoạt động tại vaydep.info/vay-co-yem-du-tiec-sang-chanh/, code dưới đây chỉ gửi đơn hàng về email mà không tạo đơn hàng trong woocommerce nhé
Code nó đây:
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 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 |
function handle_buy_now(){ global $product; ?> <div id="handle_buy_now" class="lightbox-by-id lightbox-content lightbox-white mfp-hide" style="max-width:800px ;padding:20px"> <input type="hidden" value="<?php echo $product->get_type(); ?>" id="buy_now-product-type" /> <div id="order_review" class="woocommerce-checkout-review-order"> <table class="shop_table woocommerce-checkout-review-order-table"> <thead> <tr> <th class="product-name">Sản phẩm</th> <th class="product-amount">Số lượng</th> <th class="product-total">Giá</th> </tr> </thead> <tbody> <tr class="cart_item"> <td class="product-name" > <p id="buy_now-product-title"><?php echo $product->get_name(); ?></p> <p id="buy_now-product-attribute_name"></p> <p id="buy_now-product-coupon"></p> </td> <td class="product-amount"><input id="buy_now-amount" type="number" value="1" disabled="disabled" /></td> <td class="product-total"> <span class="woocommerce-Price-amount amount" id="buy_now-price" data-bn_price=""><span class="woocommerce-Price-currencySymbol">₫</span></span> </td> </tr> </tbody> </table> <h3>Thông tin giao hàng</h3> <div class="woocommerce-billing-fields__field-wrapper"> <p class="form-row"><input type="text" class="input-text " id="buy_now_full_name" placeholder="Họ và tên *" ></p> <p class="form-row"><input type="text" class="input-text " id="buy_now_address" placeholder="Địa chỉ giao hàng *" ></p> <p class="form-row"><input type="text" class="input-text " id="buy_now_phone" placeholder="Điện thoại *" ></p> <p class="form-row"><input type="text" class="input-text " id="buy_now_email" placeholder="Email" ></p> </div> </div> <button type="button" class="button alt" id="buy_now_place_order">Đặt hàng</button> </div> <script> jQuery(function($){ $(document).ready(function(e) { //show popup $(document).on('click','a.button.alt.buy-now',function(e){ e.preventDefault(); var product_type = $('#buy_now-product-type').val(); var product_discount = $('#results-discount').data('discount_number'); var product_discount_label=number_format(product_discount)+' ₫'; var coupon_code = $('#results-discount').data('coupon_code'); product_discount=Number(product_discount); if( product_type == "variable"){ var product_variations = $('form.variations_form.cart').data('product_variations'); var pa_size = $('select#pa_size').val(); var pa_mau=$('select#pa_mau').val(); var pa_mau_label=$('#pa_mau option[value='+pa_mau+']').html(); $('#buy_now-product-attribute_name').html('Size: '+pa_size+', Màu: '+pa_mau_label); var price_number = $('.woocommerce-variation-price span.price span.woocommerce-Price-amount.amount').text().replace(".", "").replace(".", "").replace("₫", ""); price_number=Number(price_number); price_number=price_number - product_discount; var price_label = number_format(price_number)+'<span class="woocommerce-Price-currencySymbol">₫</span>'; $('#buy_now-price').html(price_label); $('#buy_now-price').data('bn_price',price_number); if(product_discount > 0){ $('#buy_now-product-coupon').html('Mã giảm giá: '+coupon_code+' ( -'+product_discount_label+' )'); } }else if(product_type == "simple"){ if($('.product-page-price').hasClass('price-on-sale')){ var amount=$('.input-text.qty.text').val(); amount=Number(amount); var price_number = $('p.price.product-page-price.price-on-sale ins span.woocommerce-Price-amount.amount').text().replace(".", "").replace(".", "").replace("₫", ""); price_number=Number(price_number); var total=amount*price_number; total=total-product_discount; var price_label = number_format(total)+'<span class="woocommerce-Price-currencySymbol">₫</span>'; $('#buy_now-price').html(price_label); $('#buy_now-price').data('bn_price',total); if(product_discount > 0){ $('#buy_now-product-coupon').html('Mã giảm giá: '+coupon_code+' ( -'+product_discount_label+' )'); } }else{ var amount=$('.input-text.qty.text').val(); amount=Number(amount); var price_number = $('p.price.product-page-price span.woocommerce-Price-amount.amount').text().replace(".", "").replace(".", "").replace("₫", ""); price_number=Number(price_number); var total=amount*price_number; total=total-product_discount; var price_label = number_format(total)+'<span class="woocommerce-Price-currencySymbol">₫</span>'; $('#buy_now-price').html(price_label); $('#buy_now-price').data('bn_price',total); if(product_discount > 0){ $('#buy_now-product-coupon').html('Mã giảm giá: '+coupon_code+' ( -'+product_discount_label+' )'); } } $('#buy_now-amount').val($('.input-text.qty.text').val()); //console.log(number_format(price_number)); } }); //buy now $(document).on('click','#buy_now_place_order',function(e){ var full_name=$('#buy_now_full_name').val(), address = $('#buy_now_address').val(), phone=$('#buy_now_phone').val(), email=$('#buy_now_email').val(), product_name=$('#buy_now-product-title').html(), product_attributes = $('#buy_now-product-attribute_name').html(), product_amount=$('#buy_now-amount').val(), product_total=$('#buy_now-price').text(), product_discount_label=$('#buy_now-product-coupon').html(); if(full_name == ''){ alert('Bạn vui lòng nhập họ tên!'); $('#buy_now_full_name').focus(); return false; } if(address == ''){ alert('Bạn vui lòng nhập địa chỉ giao hàng!'); $('#buy_now_address').focus(); return false; } if(phone == '') { alert('Bạn vui lòng nhập số điện thoại!'); $('#buy_now_phone').focus(); return false; } console.log(is_phonenumber(phone)); if(!is_phonenumber(phone)) { alert('Bạn vui lòng nhập số điện thoại hợp lệ!'); $('#buy_now_phone').focus(); return false; } if(email != ''){ if(!is_email(email)) { alert('Địa chỉ email bạn nhập không hợp lệ!'); $('#buy_now_email').focus(); return false; } } $('#buy_now_place_order').html('<span class="fa fa-circle-o-notch fa-spin"></span> Đang xử lý đơn hàng...') //ok start handle var submit_data = { action: 'vaydep_buy_now', full_name: full_name, address: address, phone: phone, email: email, product_name: product_name, product_attributes: product_attributes, product_amount: product_amount, product_total:product_total, product_discount_label: product_discount_label }; console.log(submit_data); $.ajax({ type: 'POST', url: '<?php echo admin_url('admin-ajax.php'); ?>', //url: kitimportelementor_vars.ajax_url, data: submit_data, success: function ( response ) { console.log(response); if (response.success ) { $('#buy_now_place_order').html('Đặt hàng thành công!'); location.reload(); } } }); //increase amount $(document).on('click','div#handle_buy_now',function(e){ alert('tung'); }); }); }); }); </script> <?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 |
add_action("wp_ajax_vaydep_buy_now",array($this,"vaydep_buy_now_ajax")); add_action("wp_ajax_nopriv_vaydep_buy_now",array($this,"vaydep_buy_now_ajax")); function vaydep_buy_now_send_email_to_admin($email,$data){ $to = $email; $subject = 'Đơn đặt hàng từ '.$data['full_name'].' lúc '.date('H:i').', ngày '.date('d/m/Y'); ob_start(); include(get_stylesheet_directory() . '/includes/emails/to_admin.php'); $body = ob_get_contents(); ob_end_clean(); $headers = array('Content-Type: text/html; charset=UTF-8'); $result=wp_mail( $to, $subject, $body, $headers ); return $result; } function vaydep_buy_now_send_email_to_buyer($email,$data){ $to = $email; $subject = 'Từ VayDep.Info - Đặt hàng thành công lúc '.date('H:i').', ngày '.date('d/m/Y'); ob_start(); include(get_stylesheet_directory() . '/includes/emails/to_buyer.php'); $body = ob_get_contents(); ob_end_clean(); $headers = array('Content-Type: text/html; charset=UTF-8'); $result=wp_mail( $to, $subject, $body, $headers ); return $result; } function vaydep_buy_now_ajax(){ //cac lenh xu ly o day //send email to admin $response=array(); $woocommerce_new_order_settings = get_option('woocommerce_new_order_settings'); $recipients=$woocommerce_new_order_settings['recipient']; $recipients=explode(",",$recipients); $data=$_POST; if($recipients): foreach($recipients as $email): $response[]=$this->vaydep_buy_now_send_email_to_admin($email,$data); endforeach; endif; //send email to buyer if(!empty($data['email'])){ $response[]=$this->vaydep_buy_now_send_email_to_buyer($data['email'],$data); } wp_send_json_success($response); } |
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 |
<div style="background-color:#f7f7f7;margin:0;padding:70px 0;width:100%"> <table width="100%" height="100%" cellspacing="0" cellpadding="0" border="0"> <tbody><tr><td valign="top" align="center"> <table style="background-color:#ffffff;border:1px solid #dedede;border-radius:3px" width="800" cellspacing="0" cellpadding="0" border="0"><tbody> <tr> <td valign="top" align="center"> <table style="background-color: #bf0d3d;color:#ffffff;border-bottom:0;font-weight:bold;line-height:100%;vertical-align:middle;font-family:Arial,sans-serif;border-radius:3px 3px 0 0;" width="100%" cellspacing="0" cellpadding="0" border="0"> <tbody> <tr><td style="padding:36px 48px;display:block"> <h1 style="font-family:Arial,sans-serif;font-size:30px;font-weight:300;line-height:150%;margin:0;text-align:left;color:#ffffff">Đơn đặt hàng của bạn</h1> </td> </tr> </tbody></table> </td> </tr> <tr> <td valign="top" align="center"> <table width="800" cellspacing="0" cellpadding="0" border="0"> <tbody><tr> <td style="background-color:#ffffff" valign="top"> <table width="100%" cellspacing="0" cellpadding="20" border="0"> <tbody><tr> <td style="padding:20px 20px" valign="top"> <div style="color:#636363;font-family:Arial,sans-serif;font-size:14px;line-height:150%;text-align:left"> <p style="margin:0 0 16px">Cám ơn bạn đã đặt hàng, dưới đây là thông tin đơn hàng:</p> <h2 style="color: #bf0d3d;display:block;font-family:Arial,sans-serif;font-size:18px;font-weight:bold;line-height:130%;margin:0 0 18px;text-align:left;"> Đặt hàng lúc: <?php echo date('H:i'); ?>, ngày <?php echo date('d/m/Y'); ?></h2> <div style="margin-bottom:40px"> <table style="color:#636363;border:1px solid #e5e5e5;vertical-align:middle;width:100%;font-family:Arial,sans-serif" cellspacing="0" cellpadding="6" border="1"> <thead> <tr> <th scope="col" style="color:#636363;border:1px solid #e5e5e5;vertical-align:middle;padding:12px;text-align:left">Sản phẩm</th> <th scope="col" style="color:#636363;border:1px solid #e5e5e5;vertical-align:middle;padding:12px;text-align:left">Số lượng</th> <th scope="col" style="color:#636363;border:1px solid #e5e5e5;vertical-align:middle;padding:12px;text-align:left">Giá</th> </tr> </thead> <tbody> <tr> <td style="color:#636363;border:1px solid #e5e5e5;padding:12px;text-align:left;vertical-align:middle;font-family:Arial,sans-serif;word-wrap:break-word"> <p><?php echo $data['product_name']; ?></p> <p><?php echo $data['product_attributes']; ?></p> <p><?php echo $data['product_discount_label']; ?></p> </td> <td style="color:#636363;border:1px solid #e5e5e5;padding:12px;text-align:left;vertical-align:middle;font-family:Arial,sans-serif"> <?php echo $data['product_amount']; ?></td> <td style="color:#636363;border:1px solid #e5e5e5;padding:12px;text-align:left;vertical-align:middle;font-family:Arial,sans-serif"> <?php echo $data['product_total']; ?></td> </tr> </tbody> </table> </div> <table style="width:100%;vertical-align:top;margin-bottom:40px;padding:0" cellspacing="0" cellpadding="0" border="0"> <tbody><tr> <td style="text-align:left;font-family:Arial,sans-serif;border:0;padding:0" width="50%" valign="top"> <h2 style="color: #bf0d3d;display:block;font-family:Arial,sans-serif;font-size:18px;font-weight:bold;line-height:130%;margin:0 0 18px;text-align:left;">Thông tin giao hàng:</h2> <p style="margin:0 0 16px">Họ và tên: <?php echo $data['full_name']; ?></p> <p style="margin:0 0 16px">Địa chỉ giao hàng: <?php echo $data['address']; ?></p> <p style="margin:0 0 16px">Điện thoại: <?php echo $data['phone']; ?></p> <p style="margin:0 0 16px">Email: <?php echo $data['email']; ?></p> </td> </tr> </tbody></table> </div> </td> </tr> </tbody></table> </td> </tr> </tbody></table> </td> </tr> </tbody></table> </td> </tr> </tbody></table> </div> |
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 |
<div style="background-color:#f7f7f7;margin:0;padding:70px 0;width:100%"> <table width="100%" height="100%" cellspacing="0" cellpadding="0" border="0"> <tbody><tr><td valign="top" align="center"> <table style="background-color:#ffffff;border:1px solid #dedede;border-radius:3px" width="800" cellspacing="0" cellpadding="0" border="0"><tbody> <tr> <td valign="top" align="center"> <table style="background-color: #bf0d3d;color:#ffffff;border-bottom:0;font-weight:bold;line-height:100%;vertical-align:middle;font-family:Arial,sans-serif;border-radius:3px 3px 0 0;" width="100%" cellspacing="0" cellpadding="0" border="0"> <tbody> <tr><td style="padding:36px 48px;display:block"> <h1 style="font-family:Arial,sans-serif;font-size:30px;font-weight:300;line-height:150%;margin:0;text-align:left;color:#ffffff">Đơn đặt hàng từ <?php echo $data['full_name']; ?></h1> </td> </tr> </tbody></table> </td> </tr> <tr> <td valign="top" align="center"> <table width="800" cellspacing="0" cellpadding="0" border="0"> <tbody><tr> <td style="background-color:#ffffff" valign="top"> <table width="100%" cellspacing="0" cellpadding="20" border="0"> <tbody><tr> <td style="padding:20px 20px" valign="top"> <div style="color:#636363;font-family:Arial,sans-serif;font-size:14px;line-height:150%;text-align:left"> <p style="margin:0 0 16px">Chi tiết đơn hàng:</p> <h2 style="color: #bf0d3d;display:block;font-family:Arial,sans-serif;font-size:18px;font-weight:bold;line-height:130%;margin:0 0 18px;text-align:left;"> Đặt hàng lúc: <?php echo date('H:i'); ?>, ngày <?php echo date('d/m/Y'); ?></h2> <div style="margin-bottom:40px"> <table style="color:#636363;border:1px solid #e5e5e5;vertical-align:middle;width:100%;font-family:Arial,sans-serif" cellspacing="0" cellpadding="6" border="1"> <thead> <tr> <th scope="col" style="color:#636363;border:1px solid #e5e5e5;vertical-align:middle;padding:12px;text-align:left">Sản phẩm</th> <th scope="col" style="color:#636363;border:1px solid #e5e5e5;vertical-align:middle;padding:12px;text-align:left">Số lượng</th> <th scope="col" style="color:#636363;border:1px solid #e5e5e5;vertical-align:middle;padding:12px;text-align:left">Giá</th> </tr> </thead> <tbody> <tr> <td style="color:#636363;border:1px solid #e5e5e5;padding:12px;text-align:left;vertical-align:middle;font-family:Arial,sans-serif;word-wrap:break-word"> <p><?php echo $data['product_name']; ?></p> <p><?php echo $data['product_attributes']; ?></p> <p><?php echo $data['product_discount_label']; ?></p> </td> <td style="color:#636363;border:1px solid #e5e5e5;padding:12px;text-align:left;vertical-align:middle;font-family:Arial,sans-serif"> <?php echo $data['product_amount']; ?></td> <td style="color:#636363;border:1px solid #e5e5e5;padding:12px;text-align:left;vertical-align:middle;font-family:Arial,sans-serif"> <?php echo $data['product_total']; ?></td> </tr> </tbody> </table> </div> <table style="width:100%;vertical-align:top;margin-bottom:40px;padding:0" cellspacing="0" cellpadding="0" border="0"> <tbody><tr> <td style="text-align:left;font-family:Arial,sans-serif;border:0;padding:0" width="50%" valign="top"> <h2 style="color: #bf0d3d;display:block;font-family:Arial,sans-serif;font-size:18px;font-weight:bold;line-height:130%;margin:0 0 18px;text-align:left;">Thông tin giao hàng:</h2> <p style="margin:0 0 16px">Họ và tên: <?php echo $data['full_name']; ?></p> <p style="margin:0 0 16px">Địa chỉ giao hàng: <?php echo $data['address']; ?></p> <p style="margin:0 0 16px">Điện thoại: <?php echo $data['phone']; ?></p> <p style="margin:0 0 16px">Email: <?php echo $data['email']; ?></p> </td> </tr> </tbody></table> </div> </td> </tr> </tbody></table> </td> </tr> </tbody></table> </td> </tr> </tbody></table> </td> </tr> </tbody></table> </div> |
Mọi sự sao chép xin ghi rõ nguồn là fcwordpress.net
Chuyên trang về wordpress: hướng dẫn thiết kế theme, plugin, thủ thuật wordpress