Chuyên mục

How to

71 bài viết

How to

Hướng dẫn làm phần compare products trong Woocommerce

Bước 1: Trong PHP <?php // Thêm extra fields class Extend_Attribute_Product extends WC_Product_Simple { public $fields; // Define new attribute, using for compare product } // 1. Thêm Nút So Sánh vào Sản Phẩm add_action( ‘woocommerce_after_shop_loop_item_title’, ‘woocommerce_custom_add_quick_cta’, 4 ); function woocommerce_custom_add_quick_cta(){ $product_id = get_the_ID(); $compare_products = isset($_SESSION[‘compare_products’]) ? $_SESSION[‘compare_products’] : []; $wishlist = isset($_COOKIE[‘wishlist’]) ? […]

25/12/2024·7 phút đọc
How to

Loadmore product woocommerce infinity scroll

Bước 1: Register jquery <?php add_action(‘wp_enqueue_scripts’, ‘enqueue_infinite_scroll_scripts’); function enqueue_infinite_scroll_scripts(){ if ( !is_shop() && !is_product_taxonomy() ) { return; } global $wp_query; wp_enqueue_script( ‘infinite-scroll’, THEME_URL . ‘/assets/js/infinite-scroll.js’, [‘jquery’], ‘1.0’, true ); wp_localize_script(‘infinite-scroll’, ‘lmproduct_obj’, [ ‘ajax_url’ => admin_url(‘admin-ajax.php’), ‘query_vars’ => json_encode($wp_query->query_vars), ‘nonce’ => wp_create_nonce( ‘lmp_check_nonce’ ), ‘max_num_pages’ => $wp_query->max_num_pages, ]); } ?> trong file infinite-scroll.js thêm đoạn code […]

25/12/2024·2 phút đọc
How to

Add the Meta Box Upload Multiple Images and multiple metabox

Step 1: Add Meta Boxes for Each Field Step 2: Display Each Meta Box // Profile Image Meta Box function profile_image_box_callback($post) { $image_ids = get_post_meta($post->ID, ‘profile_image_gallery’, true); $image_ids = is_array($image_ids) ? $image_ids : []; wp_nonce_field(‘profile_image_box_nonce’, ‘profile_image_box_nonce_field’); ?> <div id=”profile-image-gallery-wrapper”> <ul class=”custom-images-list”> <?php foreach ($image_ids as $image_id) : ?> <li> <?php echo wp_get_attachment_image($image_id, ‘thumbnail’); ?> <a […]

03/10/2024·3 phút đọc
How to

Add the Meta Box Repeat

Add the Meta Box // Register the meta box function wp_custom_meta_box() { add_meta_box( ‘custom_meta_box’, // ID ‘Custom Meta Box’, // Title ‘wp_custom_meta_box_html’, // Callback function ‘post’, // Post type ‘normal’, // Context ‘high’ // Priority ); } add_action(‘add_meta_boxes’, ‘wp_custom_meta_box’); function wp_custom_meta_box_html($post) { wp_nonce_field(‘save_custom_meta_box’, ‘custom_meta_box_nonce’); // Get existing data if available $meta_data = get_post_meta($post->ID, ‘_custom_meta_box’, true); […]

03/10/2024·2 phút đọc
How toJavascript

Kỹ thuật debounce trong javascript – Trì hoãn nhập từ khóa trong ô input

HTML <div class=”seachbox”> <input type=”text” name=”seach-text” id=”seach-text”> </div> Javascript: function delay(callback, ms) { var timer = 0; return function () { var context = this, args = arguments; clearTimeout(timer); timer = setTimeout(function () { callback.apply(context, args); }, ms || 0); }; } $(‘#seach-text’).keyup( delay(function (e) { console.log(‘Time elapsed!’, this.value); }, 500) );  

03/10/2024·1 phút đọc
How to

Thêm VS Code snippets

{ // Place your snippets for php here. Each snippet is defined under a snippet name and has a prefix, body and // description. The prefix is what is used to trigger the snippet and the body will be expanded and inserted. Possible variables are: // $1, $2 for tab stops, $0 for the final […]

01/10/2024·2 phút đọc
How to

Query only seach by title

Hook only seach by title in page seach function wpse_11826_search_by_title( $search, $wp_query ) { if ( ! empty( $search ) && ! empty( $wp_query->query_vars[‘search_terms’] ) ) { global $wpdb; $q = $wp_query->query_vars; $n = ! empty( $q[‘exact’] ) ? ” : ‘%’; $search = array(); foreach ( ( array ) $q[‘search_terms’] as $term ) $search[] […]

24/09/2024·1 phút đọc
How to

Hướng dẫn tạo form có validate, upload file nhiều bước và xử lý ajax

B1: Đăng ký thư viện trong admin WordPress function tmdev_add_style_scripts() { $js_list_an_item_ver = date(“ymd-Gis”, filemtime( get_template_directory(). ‘/assets/js/list-an-item.js’ )); $assets_path = get_template_directory_uri(); wp_enqueue_script(‘jquery-validation’, $assets_path.’/assets/js/jquery.validate.min.js’, array(‘jquery’)); wp_enqueue_script(‘product-submit’, $assets_path.’/assets/js/list-an-item.js’, array(‘jquery’, ‘custom-script’), $js_list_an_item_ver ); wp_enqueue_style( ‘product-submit’, $assets_path.’/assets/css/product-submit.css’, ”, 123 ); } add_action( ‘wp_enqueue_scripts’, ‘tmdev_add_style_scripts’ ); B2: Tạo form và xử lý validate ở ngoài Frontend <div id=”product-submission-form”> <div class=”step-buttons”> […]

23/09/2024·6 phút đọc
How to

Chia sẻ một số thư viện loading css đẹp

Bạn đang cần xử lý dữ liệu bằng Ajax, trong khi chờ tải dữ liệu bạn nên có một dấu hiệu gì đó báo cho người truy cập website của bạn biết rằng dữ liệu đang được tải, một trong những dấu hiệu đó là thêm icon loading, và mình có tìm được một số […]

25/03/2024·1 phút đọc