{"id":2689,"date":"2023-10-12T14:10:00","date_gmt":"2023-10-12T07:10:00","guid":{"rendered":"https:\/\/shopcode.vn\/?p=2689"},"modified":"2023-10-25T17:12:33","modified_gmt":"2023-10-25T10:12:33","slug":"tao-nut-mua-ngay-ben-duoi-san-pham-trong-woocommerce","status":"publish","type":"post","link":"https:\/\/shopcode.vn\/tao-nut-mua-ngay-ben-duoi-san-pham-trong-woocommerce\/","title":{"rendered":"T\u1ea1o n\u00fat \u201cmua ngay\u201d b\u00ean d\u01b0\u1edbi s\u1ea3n ph\u1ea9m trong Woocommerce"},"content":{"rendered":"
Theo giao di\u1ec7n m\u1eb7c \u0111\u1ecbnh c\u1ee7a woocommerce s\u1ebd lu\u00f4n c\u00f3 m\u1ed9t n\u00fat \u201cTh\u00eam v\u00e0o gi\u1ecf h\u00e0ng\u201d, nh\u01b0ng trong m\u1ed9t s\u1ed1 tr\u01b0\u1eddng h\u1ee3p b\u1ea1n mu\u1ed1n l\u00e0m theo c\u00e1c trang th\u01b0\u01a1ng m\u1ea1i \u0111i\u1ec7n t\u1eed, \u0111\u00f3 l\u00e0 th\u00eam m\u1ed9t n\u00fat \u201cmua ngay\u201d v\u00e0o k\u1ebf b\u00ean n\u00fat \u201cth\u00eam v\u00e0o gi\u1ecf h\u00e0ng\u201d b\u1ea1n ch\u1ec9 c\u1ea7n l\u00e0m theo c\u00e1c b\u01b0\u1edbc d\u01b0\u1edbi \u0111\u00e2y l\u00e0 \u0111\u01b0\u1ee3c nh\u00e9.<\/p>\n
Th\u1ef1c ch\u1ea5t n\u00fat \u201cmua ngay\u201d l\u00e0 thao t\u00e1c \u0111\u01b0a ng\u01b0\u1eddi mua h\u00e0ng \u0111i th\u1eb3ng \u0111\u1ebfn trang thanh to\u00e1n ho\u1eb7c b\u1ea1n c\u0169ng c\u00f3 th\u1ec3 custom th\u00e0nh trang gi\u1ecf h\u00e0ng.<\/p>\n
\u01afu \u0111i\u1ec3m c\u1ee7a code th\u00eam n\u00fat mua ngay v\u00e0o woocommerce:<\/strong><\/p>\n C\u00e1ch th\u00eam n\u00fat mua ngay v\u00e0o woocommerce nhanh ch\u00f3ng:<\/strong><\/p>\n \u0110\u1ec3 th\u00eam n\u00fat mua ngay v\u00e0o trang product page trong woocommerce s\u1eed d\u1ee5ng giao di\u1ec7n flatsome r\u1ea5t d\u1ec5 d\u00e0ng, b\u1ea1n ch\u1ec9 c\u1ea7n copy v\u00e0 paste \u0111o\u1ea1n code d\u01b0\u1edbi \u0111\u00e2y v\u00e0o file function.php l\u00e0 \u0111\u01b0\u1ee3c.<\/p>\n L\u01b0u \u00fd: \u0110\u1ec3 \u0111\u1ea3m b\u1ea3o an to\u00e0n, n\u1ebfu b\u1ea1n ch\u01b0a r\u00e0nh v\u1ec1 s\u1eeda website th\u00ec n\u00ean backup website l\u1ea1i tr\u01b0\u1edbc khi s\u1eeda. C\u00e1ch t\u1ed1t nh\u1ea5t l\u00e0 b\u1ea1n h\u00e3y th\u00eam code v\u00e0o file fuction trong child theme, \u0111\u1eebng s\u1eeda tr\u1ef1c ti\u1ebfp trong theme m\u1eb9 nha.<\/p>\n <\/p>\n V\u1edbi vi\u1ec7c th\u00eam \u0111o\u1ea1n code tr\u00ean l\u00e0 website c\u1ee7a b\u1ea1n \u0111\u00e3 xu\u1ea5t hi\u1ec7n button Mua ngay tr\u00ean trang s\u1ea3n ph\u1ea9m r\u1ed3i.<\/p>\n Tuy nhi\u00ean, n\u1ebfu b\u1ea1n mu\u1ed1n chuy\u1ec3n h\u01b0\u1edbng \u0111\u1ebfn trang gi\u1ecf h\u00e0ng thay v\u00ec chuy\u1ec3n th\u1eb3ng \u0111\u1ebfn trang thanh to\u00e1n th\u00ec s\u1eeda l\u1ea1i \u0111o\u1ea1n code sau \u1edf d\u00f2ng 27:<\/p>\n t\u1eeb nh\u01b0 n\u00e0y:<\/p>\n th\u00e0nh nh\u01b0 n\u00e0y:<\/p>\n Xong, \u0111\u01a1n gi\u1ea3n v\u1eady th\u00f4i. H\u00e3y ra trang s\u1ea3n ph\u1ea9m v\u00e0 xem th\u1eed th\u00e0nh qu\u1ea3 nh\u00e9.<\/p>\n \u0110o\u1ea1n code n\u00e0y \u0111\u00e3 \u0111\u01b0\u1ee3c test v\u1edbi bi\u1ec3n th\u1ec3 m\u1eb7c \u0111\u1ecbnh c\u1ee7a giao di\u1ec7n woocommerce.<\/p>\n","protected":false},"excerpt":{"rendered":" H\u01b0\u1edbng d\u1eabn th\u00eam n\u00fat mua ngay v\u00e0o woocommerce Theo giao di\u1ec7n m\u1eb7c \u0111\u1ecbnh c\u1ee7a woocommerce s\u1ebd lu\u00f4n c\u00f3 m\u1ed9t n\u00fat \u201cTh\u00eam v\u00e0o gi\u1ecf h\u00e0ng\u201d, nh\u01b0ng trong m\u1ed9t s\u1ed1 tr\u01b0\u1eddng h\u1ee3p b\u1ea1n mu\u1ed1n l\u00e0m theo c\u00e1c trang th\u01b0\u01a1ng m\u1ea1i \u0111i\u1ec7n t\u1eed, \u0111\u00f3 l\u00e0 th\u00eam m\u1ed9t n\u00fat \u201cmua ngay\u201d v\u00e0o k\u1ebf b\u00ean n\u00fat \u201cth\u00eam v\u00e0o gi\u1ecf h\u00e0ng\u201d …<\/p>\n","protected":false},"author":2,"featured_media":2690,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"_acf_changed":false,"footnotes":""},"categories":[1,65,1042],"tags":[1047],"acf":[],"yoast_head":"\n\n
\/*\r\n* Add quick buy button go to checkout after click\r\n* Author: Shopcode.vn\r\n*\/\r\nadd_action('woocommerce_after_add_to_cart_button','devvn_quickbuy_after_addtocart_button');\r\nfunction devvn_quickbuy_after_addtocart_button(){\r\n global $product;\r\n ?>\r\n <style>\r\n .devvn-quickbuy button.single_add_to_cart_button.loading:after {\r\n display: none;\r\n }\r\n .devvn-quickbuy button.single_add_to_cart_button.button.alt.loading {\r\n color: #fff;\r\n pointer-events: none !important;\r\n }\r\n .devvn-quickbuy button.buy_now_button {\r\n position: relative;\r\n color: rgba(255,255,255,0.05);\r\n }\r\n .devvn-quickbuy button.buy_now_button:after {\r\n animation: spin 500ms infinite linear;\r\n border: 2px solid #fff;\r\n border-radius: 32px;\r\n border-right-color: transparent !important;\r\n border-top-color: transparent !important;\r\n content: \"\";\r\n display: block;\r\n height: 16px;\r\n top: 50%;\r\n margin-top: -8px;\r\n left: 50%;\r\n margin-left: -8px;\r\n position: absolute;\r\n width: 16px;\r\n }\r\n <\/style>\r\n <button type=\"button\" class=\"button buy_now_button\">\r\n <?php _e('Mua ngay', 'devvn'); ?>\r\n <\/button>\r\n <input type=\"hidden\" name=\"is_buy_now\" class=\"is_buy_now\" value=\"0\" autocomplete=\"off\"\/>\r\n <script>\r\n jQuery(document).ready(function(){\r\n jQuery('.is_buy_now').val('0');\r\n jQuery('body').on('click', '.buy_now_button', function(e){\r\n e.preventDefault();\r\n var thisParent = jQuery(this).parents('form.cart');\r\n if(jQuery('.single_add_to_cart_button', thisParent).hasClass('disabled')) {\r\n jQuery('.single_add_to_cart_button', thisParent).trigger('click');\r\n return false;\r\n }\r\n thisParent.addClass('devvn-quickbuy');\r\n jQuery('.is_buy_now', thisParent).val('1');\r\n jQuery('.single_add_to_cart_button', thisParent).trigger('click');\r\n });\r\n });\r\n jQuery( document.body ).on( 'added_to_cart', function (e, fragments, cart_hash, addToCartButton){\r\n let thisForm = addToCartButton.closest('.cart');\r\n let is_buy_now = parseInt(jQuery('.is_buy_now', thisForm).val()) || 0;\r\n if(is_buy_now === 1 && typeof wc_add_to_cart_params !== \"undefined\") {\r\n window.location = wc_add_to_cart_params.cart_url;\r\n }\r\n });\r\n <\/script>\r\n <?php\r\n}\r\nadd_filter('woocommerce_add_to_cart_redirect', 'redirect_to_checkout');\r\nfunction redirect_to_checkout($redirect_url) {\r\n if(!get_theme_mod( 'ajax_add_to_cart' )) {\r\n if (isset($_REQUEST['is_buy_now']) && $_REQUEST['is_buy_now'] && get_option('woocommerce_cart_redirect_after_add') !== 'yes') {\r\n $redirect_url = wc_get_checkout_url(); \/\/or wc_get_cart_url()\r\n }\r\n }\r\n return $redirect_url;\r\n}\r\nadd_filter('woocommerce_get_script_data', 'devvn_woocommerce_get_script_data', 10, 2);\r\nfunction devvn_woocommerce_get_script_data($params, $handle) {\r\n if($handle == 'wc-add-to-cart'){\r\n $params['cart_url'] = wc_get_checkout_url();\r\n }\r\n return $params;\r\n}<\/pre>\n
\n\n
\n \n \n \n\n
\n \n \n