• Resolved naastech2019

    (@naastech2019)


    I use this plugin on the live site environment, product hidden function is not working and after collapsing the time product is still available live.

Viewing 3 replies - 1 through 3 (of 3 total)
  • Hi @naastech2019,

    We need to check your website directly to find out the issue. If you don’t want to activate your plugin on your live site, you can create a dev/staging site with the same configuration, then we’ll work on it.

    Regards,

    Plugin Author WPClever

    (@wpclever)

    Hi @naastech2019

    Please also try the below snippet (How to add custom code?):

    add_action( 'pre_get_posts', 'woopt_pre_get_posts', 99 );
    
    function woopt_pre_get_posts( $query ) {
    	if ( is_admin() || ( is_singular() && $query->is_main_query() ) ) {
    		return $query;
    	}
    
    	$post_type = $query->get( 'post_type' );
    
    	if ( ( $post_type === 'product' ) || ( is_array( $post_type ) && in_array( 'product', $post_type ) ) ) {
    		global $wpdb;
    		$exclude_ids = $query->get( 'post__not_in' );
    		$products    = $wpdb->get_results( "SELECT id FROM $wpdb->posts WHERE post_type = 'product' AND post_status = 'publish' LIMIT 500", OBJECT );
    
    		if ( count( $products ) > 0 ) {
    			foreach ( $products as $pr ) {
    				$visible = WPCleverWoopt::woopt_is_visible( true, $pr->id );
    
    				if ( ! $visible ) {
    					// push to old values
    					array_push( $exclude_ids, $pr->id );
    				}
    			}
    
    			$query->set( 'post__not_in', $exclude_ids );
    		}
    	}
    
    	return $query;
    }
    Thread Starter naastech2019

    (@naastech2019)

    Thank you so much. Its working.

Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘Product Hidden Not working’ is closed to new replies.