drowosek
Forum Replies Created
-
Forum: Plugins
In reply to: [YITH Infinite Scrolling] How to stop infinity scrollMaybe it will be useful for somebody. I solved this problem:
This code for turn off plugin (I insert it after receiving ajax data)
$( window ).on( 'scroll touchstart', function (){ $(this).trigger('yith_infs_start').off("scroll"); $(this).trigger('yith_infs_start').off("touchstart"); });
This code for turn on plugin (I insert it in a function which is run when filter is clean)
$( window ).on( 'scroll touchstart', function (){ $(this).trigger('yith_infs_start').on("scroll"); $(this).trigger('yith_infs_start').on("touchstart"); });
I know that it is not a perfect solution because we can use
.off("scroll","touchstart")
but in my case it does not work.- This reply was modified 2 years, 8 months ago by drowosek.
Forum: Plugins
In reply to: [YITH Infinite Scrolling] How to stop infinity scrollI solved this issue, with inserting this code:
$( window ).on( 'scroll touchstart', function (){ $(this).trigger('yith_infs_start').off(); });
but I have another one problem after the cleaning filter, I try to re-initialize infinity scrolling like this
$( window ).on( 'scroll touchstart', function (){ $(this).trigger('yith_infs_start').on(); });
but it`s not working.
Forum: Plugins
In reply to: [YITH Infinite Scrolling] How to stop infinity scrollThank you for your hint! I tried to block event scroll, but it does not work. Maybe I used it incorrect. I insert this code after ajax response. I think logically it is good. Could you check it?
$( window ).on( 'scroll touchstart', function (){ $(this).trigger('yith_infs_start'); }); $( window ).on( 'yith_infs_start', function (){ return false; });
- This reply was modified 2 years, 8 months ago by drowosek.
Forum: Fixing WordPress
In reply to: Custom ajax filter by termsmaybe, somebody will need it, i solve this issue.
function product_scripts() { wp_register_script('custom-script', get_stylesheet_directory_uri() . '/lib/ajax-products-filter.js', array('jquery'), false, true); $script_data_array = array( 'ajaxurl' => admin_url('admin-ajax.php'), 'security' => wp_create_nonce('load_products'), ); wp_localize_script('custom-script', 'blog', $script_data_array); wp_enqueue_script('custom-script'); } add_action('wp_enqueue_scripts', 'product_scripts'); add_action('wp_ajax_load_posts_by_ajax', 'load_posts_by_ajax_callback'); add_action('wp_ajax_nopriv_load_posts_by_ajax', 'load_posts_by_ajax_callback'); function load_posts_by_ajax_callback() { check_ajax_referer('load_products', 'security'); $paged = $_POST['page']; $category = $_POST['category']; $colors = $_POST['colors']; ?> <ul class="products results-js" style="display: grid"> <?php $args = array( 'post_type' => 'product', 'post_status' => 'publish', 'posts_per_page' => -1, 'paged' => $paged, 'meta_query' => array( 'key' => '_visibility', 'value' => array('catalog', 'visible'), 'compare' => 'IN', ), 'tax_query' => array( 'relation' => 'AND', array( 'relation' => 'OR', array( 'taxonomy' => 'product_cat', 'field' => 'slug', 'terms' => $category, 'operator' => 'IN', ), array( 'taxonomy' => 'by-gift', 'field' => 'slug', 'terms' => $category, 'operator' => 'IN', ), array( 'taxonomy' => 'by-room', 'field' => 'slug', 'terms' => $category, 'operator' => 'IN', ), ), array( 'taxonomy' => 'pa_colors', 'field' => 'name', 'terms' => $colors, 'operator' => 'IN', ) ) ); $loop= new WP_Query($args); if ( $loop->have_posts() ) { while ( $loop->have_posts() ) : $loop->the_post(); wc_get_template_part( 'content', 'product' ); endwhile; } else { echo __( '<p class="woocommerce-info">No products were found matching your selection.</p>' ); } wp_reset_postdata(); ?> </ul> <?php wp_die(); }
Forum: Fixing WordPress
In reply to: Custom ajax filter by termsProblem solved partly, now I recieve products by colors, but not by category. I think something wrong in query by category..
$args = array( 'post_type' => 'product', 'post_status' => 'publish', 'posts_per_page' => -1, 'paged' => $paged, 'meta_query' => array( 'key' => '_visibility', 'value' => array('catalog', 'visible'), 'compare' => 'IN', ), 'tax_query' => array( 'relation' => 'AND', array( 'taxonomy' => 'products-cat', 'field' => 'slug', 'terms' => $category, 'operator' => 'IN', ), array( 'taxonomy' => 'pa_colors', 'field' => 'name', 'terms' => $colors, 'operator' => 'IN', ) ) );
Forum: Fixing WordPress
In reply to: Custom ajax filter by termsPartly solved, but I recieve all the products
$('.button-filter').click(function () { var page = 1; if ( $(this).hasClass('active-js')){ $(this).removeClass('active-js') }else{ $(this).addClass('active-js') $('.clear-js').fadeIn() } var colors = []; $('.button-filter.active-js').each(function (){ var r = $(this).data('color'); colors.push(r); }) if (colors.length == 0){ clearFilter() } console.log(colors) var category = $('.page-title').html() console.log(category) var data = { 'action': 'load_posts_by_ajax', 'security': blog.security, 'page': page, 'category': category, 'colors': colors, }; console.log(data) $.post(blog.ajaxurl, data, function (response) { console.log(response) if ($.trim(response) != '') { console.log(response) $('.products').fadeOut() $('.all-product-grid').fadeOut() $('#wc-column-container').append(response); page++; } }); }); function clearFilter(){ $('.button-filter').each(function () { $(this).removeClass('active-js') $('.clear-js').fadeOut() $('.products').fadeIn() $('.all-product-grid').fadeIn() }) }
and php
function product_scripts() { wp_register_script('custom-script', get_stylesheet_directory_uri() . '/lib/ajax-products-filter.js', array('jquery'), false, true); $script_data_array = array( 'ajaxurl' => admin_url('admin-ajax.php'), 'security' => wp_create_nonce('load_products'), ); wp_localize_script('custom-script', 'blog', $script_data_array); wp_enqueue_script('custom-script'); } add_action('wp_enqueue_scripts', 'product_scripts'); add_action('wp_ajax_load_posts_by_ajax', 'load_posts_by_ajax_callback'); add_action('wp_ajax_nopriv_load_posts_by_ajax', 'load_posts_by_ajax_callback'); function load_posts_by_ajax_callback() { check_ajax_referer('load_products', 'security'); $paged = $_POST['page']; $category = $_POST['category']; $colors = $_POST['colors']; ?> <ul class="products-js"> <?php $loop = new WP_Query(array( 'post_type' => 'product', 'category' => $category, 'post_status' => 'publish', 'posts_per_page' => -1, 'paged' => $paged, 'meta_query' => array( 'key' => '_visibility', 'value' => array('catalog', 'visible'), 'compare' => 'IN', ), 'tax_query' => array( 'taxonomy' => 'pa_colors', 'field' => 'slug', 'terms' => $colors, 'operator' => 'IN', ) )); if ( $loop->have_posts() ) { while ( $loop->have_posts() ) : $loop->the_post(); wc_get_template_part( 'content', 'product' ); endwhile; } else { echo __( 'No products found' ); } wp_reset_postdata(); ?> </ul><!–/.products–> <?php wp_die(); }
Forum: Fixing WordPress
In reply to: Change product card template woocommerceI just made the wrap before and after 7th product and it works