Forum Replies Created

Viewing 4 replies - 1 through 4 (of 4 total)
  • Thread Starter doreoo

    (@doreoo)

    Hi Herman,

    yes exactly, problem resolved!

    Thread Starter doreoo

    (@doreoo)

    Hi Herman,

    finally solved the problem. It was caused by the smush plugin`s lazyload function. I just added .custom-logo to Classes & IDs to avoid and now it works.

    Thanks.

    Thread Starter doreoo

    (@doreoo)

    Finally found the problem!

    I just changed ‘meta_value_num’ to ‘meta_value_num meta_value’. There were some people on the internet who had similar issues with their blog sites + infinite scroll.

    I took me days to built a complete working “views sorting option” because i dont have any php skills at all xD.

    Thread Starter doreoo

    (@doreoo)

    Thanks for the answer!

    Buit and added one by my own now with codes from the internet.

    add_action( 'woocommerce_before_single_product', 'prefix_save_product_views' );
    function prefix_save_product_views(  ) {
    
        $product_id = get_the_ID();
        $increment = 1;
        $current_visit_count = get_post_meta( $product_id, 'product_visit_count', true );
    
        $total_visit_count = (int)$current_visit_count + $increment;
        update_post_meta( $product_id, 'product_visit_count', $total_visit_count );
    
    }
    
    add_filter( 'woocommerce_catalog_orderby', 'misha_add_custom_sorting_options' );
     
    function misha_add_custom_sorting_options( $options ){
     
    	$options['popular'] = 'Beliebteste';
    	
    	return $options;
     
    }
    
    add_filter( 'woocommerce_get_catalog_ordering_args', 'misha_custom_product_sorting' );
     
    function misha_custom_product_sorting( $args ) {
     
    	// Nach Aufrufen sortieren
    	if ( isset( $_GET['orderby'] ) && 'popular' === $_GET['orderby'] ) {
    	$args['meta_key'] = 'product_visit_count';
        $args['orderby'] = 'meta_value_num';
        $args['order'] = 'desc';
    		}
        return $args;
    }

    Only Problem is that when I use this sort option some products or product rows show twice. With other sort options ( newest,price,etc…) i dont have this problem.

Viewing 4 replies - 1 through 4 (of 4 total)