Forum Replies Created

Viewing 15 replies - 1 through 15 (of 355 total)
  • same here too. semrush is popping up “structured data items are invalid” errors for clients’ site. this is rather annoying. please fix this soon. thank you.

    Thread Starter Jason Wong

    (@eljkmw)

    @devnihil

    I found this thread, which Karel-Jan Tolsma mentioned that by pumping up the memory_limit to 1024 MB helps to remove this issue.

    So far, it appears as though this increase of the memory_limit is working. I’ll continue monitoring until end of this month.

    Thread Starter Jason Wong

    (@eljkmw)

    @donncha
    The master timezone is set to UTC by the hosting provider, while I can set the local timezone either via .htaccess or php.ini. I’m not using any virtual host, but a shared host.

    Thread Starter Jason Wong

    (@eljkmw)

    I’ve proceeded with Question 4, and I noticed the error_log file is logged whenever and wherever wp-admin is accessed. By the way, this happens to either Yoast SEO 15.6.2 and Yoast SEO Premium 14.8.

    Thread Starter Jason Wong

    (@eljkmw)

    To answer your questions.

    1. YES
    WordPress 5.6
    PHP 7.4.13
    PHP Memory 512MB
    MariaDB 10.2.36
    
    2. YES.  All plugins are up to date
    3. YES.  Yoast SEO 15.6.2
    4. I'll test this in the next 48 hours, and update here later.
    Thread Starter Jason Wong

    (@eljkmw)

    Just ran a test with both local and master values being the same at UTC, and the results are still the same. This is very odd indeed.

    Thread Starter Jason Wong

    (@eljkmw)

    @donncha Did you check your system’s PHP info on whether the local and master values of date.timezone are identical, or difference? I’m guessing if they’re different, the timestamps will definitely be different and the pages won’t cache.

    Thread Starter Jason Wong

    (@eljkmw)

    Apparently WC_Query sorts prices differently, and it cannot be modified in a simple fashion. Eventually, I managed to work out a solution to my problem, and apply the same $orderby[‘price’] and $orderby[‘price-desc’] without introducing new ones.

    The snippets are as follows.

    // Add catalog order by arguments
    function wc_add_catalog_orderby_args( $sort_args ) {
    
    	$orderby_value = isset( $_GET['orderby'] ) ? wc_clean( $_GET['orderby'] ) : apply_filters( 'woocommerce_default_catalog_orderby', get_option( 'woocommerce_default_catalog_orderby' ) );
    
    	switch( $orderby_value ) {
    
    		case 'name':
    			$sort_args['orderby'] = 'title';
    			$sort_args['order']   = 'asc';
    		break;
    
    		case 'name-desc':
    			$sort_args['orderby']  = 'title';
    			$sort_args['order']    = 'desc';
    		break;
    
    		case 'price':
    			WC()->query->remove_ordering_args();    // remove ordering queries
    			$sort_args['meta_key'] = '_price';
    			$sort_args['orderby']  = ['meta_value_num' => 'asc', 'title' => 'asc'];
    		break;
    
    		case 'price-desc':
    			WC()->query->remove_ordering_args();    // remove ordering queries
    			$sort_args['meta_key'] = '_price';
    			$sort_args['orderby']  = ['meta_value_num' => 'desc', 'title' => 'asc'];
    		break;
    	}
    
    	return $sort_args;
    }
    add_filter( 'woocommerce_get_catalog_ordering_args', 'wc_add_catalog_orderby_args' );
    
    // Custom default catalog orderby options
    function wc_custom_catalog_orderby_options( $orderby ) {
    
    	// Remove "Default sorting"
    	if ( isset( $orderby['menu_order'] ) )      unset( $orderby['menu_order'] );
    
            // Remove "Sort by popularity"
    	if ( isset( $orderby['popularity'] ) )      unset( $orderby['popularity'] );
    
            // Remove "Sort by average rating"
    	if ( isset( $orderby['rating'] ) )          unset( $orderby['rating'] );
    
            // Remove "Sort by newness"
    	if ( isset( $orderby['date'] ) )            unset( $orderby['date'] );
    
            // Remove "Sort by price: low to high"
    	if ( isset( $orderby['price'] ) )           unset( $orderby['price'] );
    
            // Remove "Sort by price: high to low"
    	if ( isset( $orderby['price-desc'] ) )      unset( $orderby['price-desc'] );
    
    	$orderby['name']        = "Sort by Name: A to Z";
    	$orderby['name-desc'] 	= "Sort by Name: Z to A";
    	$orderby['price'] 	= "Sort by Price: low to high";
    	$orderby['price-desc'] 	= "Sort by Price: high to low";
    
    	return $orderby;
    }
    add_filter( 'woocommerce_catalog_orderby', 'wc_custom_catalog_orderby_options' );
    add_filter( 'woocommerce_default_catalog_orderby_options', 'wc_custom_catalog_orderby_options' );

    I had to use WC()->query->remove_ordering_args(); to remove the default ordering queries prior to configuring both ‘price’ and ‘price-desc’ to different ordering queries.

    Hope this will be helpful to someone else.

    Thread Starter Jason Wong

    (@eljkmw)

    Thread Starter Jason Wong

    (@eljkmw)

    The following snippets don’t work …

    // Add catalog order by arguments
    function wc_add_catalog_orderby_args( $sort_args ) {
    
    	$orderby_value = isset( $_GET['orderby'] ) ? wc_clean( $_GET['orderby'] ) : apply_filters( 'woocommerce_default_catalog_orderby', get_option( 'woocommerce_default_catalog_orderby' ) );
    
    	switch( $orderby_value ) {
    
    		case 'name':
    			$sort_args['orderby'] = 'title';
    			$sort_args['order']   = 'asc';
    		break;
    
    		case 'name-desc':
    			$sort_args['orderby']  = 'title';
    			$sort_args['order']    = 'desc';
    		break;
    
    		case 'price':
    			$sort_args['meta_key'] = '_price';
    			$sort_args['orderby']  = ['meta_value_num' => 'asc', 'title' => 'asc'];
    		break;
    
    		case 'price-desc':
    			$sort_args['meta_key'] = '_price';
    			$sort_args['orderby']  = ['meta_value_num' => 'desc', 'title' => 'asc'];
    		break;
    	}
    
    	return $sort_args;
    }
    add_filter( 'woocommerce_get_catalog_ordering_args', 'wc_add_catalog_orderby_args' );
    
    // Custom default catalog orderby options
    function wc_custom_catalog_orderby_options( $orderby ) {
    
    	// Remove "Default sorting"
    	if ( isset( $orderby['menu_order'] ) )      unset( $orderby['menu_order'] );
    
            // Remove "Sort by popularity"
    	if ( isset( $orderby['popularity'] ) )      unset( $orderby['popularity'] );
    
            // Remove "Sort by average rating"
    	if ( isset( $orderby['rating'] ) )          unset( $orderby['rating'] );
    
            // Remove "Sort by newness"
    	if ( isset( $orderby['date'] ) )            unset( $orderby['date'] );
    
            // Remove "Sort by price: low to high"
    	if ( isset( $orderby['price'] ) )           unset( $orderby['price'] );
    
            // Remove "Sort by price: high to low"
    	if ( isset( $orderby['price-desc'] ) )      unset( $orderby['price-desc'] );
    
    	$orderby['name']        = "Sort by Name: A to Z";
    	$orderby['name-desc'] 	= "Sort by Name: Z to A";
    	$orderby['price'] 	= "Sort by Price: low to high";
    	$orderby['price-desc'] 	= "Sort by Price: high to low";
    
    	return $orderby;
    }
    add_filter( 'woocommerce_catalog_orderby', 'wc_custom_catalog_orderby_options' );
    add_filter( 'woocommerce_default_catalog_orderby_options', 'wc_custom_catalog_orderby_options' );

    But, these do …

    // Add catalog order by arguments
    function wc_add_catalog_orderby_args( $sort_args ) {
    
    	$orderby_value = isset( $_GET['orderby'] ) ? wc_clean( $_GET['orderby'] ) : apply_filters( 'woocommerce_default_catalog_orderby', get_option( 'woocommerce_default_catalog_orderby' ) );
    
    	switch( $orderby_value ) {
    
    		case 'name':
    			$sort_args['orderby'] = 'title';
    			$sort_args['order']   = 'asc';
    		break;
    
    		case 'name-desc':
    			$sort_args['orderby']  = 'title';
    			$sort_args['order']    = 'desc';
    		break;
    
    		case 'cost':
    			$sort_args['meta_key'] = '_price';
    			$sort_args['orderby']  = ['meta_value_num' => 'asc', 'title' => 'asc'];
    		break;
    
    		case 'cost-desc':
    			$sort_args['meta_key'] = '_price';
    			$sort_args['orderby']  = ['meta_value_num' => 'desc', 'title' => 'asc'];
    		break;
    	}
    
    	return $sort_args;
    }
    add_filter( 'woocommerce_get_catalog_ordering_args', 'wc_add_catalog_orderby_args' );
    
    // Custom default catalog orderby options
    function wc_custom_catalog_orderby_options( $orderby ) {
    
    	// Remove "Default sorting"
    	if ( isset( $orderby['menu_order'] ) )      unset( $orderby['menu_order'] );
    
            // Remove "Sort by popularity"
    	if ( isset( $orderby['popularity'] ) )      unset( $orderby['popularity'] );
    
            // Remove "Sort by average rating"
    	if ( isset( $orderby['rating'] ) )          unset( $orderby['rating'] );
    
            // Remove "Sort by newness"
    	if ( isset( $orderby['date'] ) )            unset( $orderby['date'] );
    
            // Remove "Sort by price: low to high"
    	if ( isset( $orderby['price'] ) )           unset( $orderby['price'] );
    
            // Remove "Sort by price: high to low"
    	if ( isset( $orderby['price-desc'] ) )      unset( $orderby['price-desc'] );
    
    	$orderby['name']        = "Sort by Name: A to Z";
    	$orderby['name-desc'] 	= "Sort by Name: Z to A";
    	$orderby['cost'] 	= "Sort by Price: low to high";
    	$orderby['cost-desc'] 	= "Sort by Price: high to low";
    
    	return $orderby;
    }
    add_filter( 'woocommerce_catalog_orderby', 'wc_custom_catalog_orderby_options' );
    add_filter( 'woocommerce_default_catalog_orderby_options', 'wc_custom_catalog_orderby_options' );

    I’m truly puzzled as to why $orderby[‘price’] and $orderby[‘price-desc’] cannot be applied. Does anyone have any explanation for this?

    Thanks in advance.

    Thread Starter Jason Wong

    (@eljkmw)

    Here are the examples…

    Title sorted in an ascending order only

    Apple - 8
    Banana - 5
    Carrot - 2
    Cucumber - 2
    Grapes - 7
    Guava - 5
    Kiwi - 7
    Orange - 4
    Peach - 7
    Pear - 6

    Price and title are sorted in an ascending order together

    Apple - 8
    Grapes - 7
    Kiwi - 7
    Peach - 7
    Pear - 6
    Banana - 5
    Guava - 5
    Orange - 4
    Carrot - 2
    Cucumber - 2

    Price is sorted in an descending order but title is in an ascending order together

    Carrot - 2
    Cucumber - 2
    Orange - 4
    Banana - 5
    Guava - 5
    Pear - 6
    Grapes - 7
    Kiwi - 7
    Peach - 7
    Apple - 8

    @pickme

    Is your product’s category hierarchy as such: Men > Clothes > Shirts
    Then, I’m assuming you want your product’s permalink to look like, https://example.com/e-shop/men/clothes/shirts/sample-product/
    Yes?

    If so, you can use Premmerce Permalink Manager for WooCommerce. I use it for my WooCommerce website, and it works well.

    Hope this helps.

    @candyemporium

    Please check that “Show subcategories” is selected for “Category display” within wp-admin > Appearance > Customize > WooCommerce > Product Catalog

    Forum: Plugins
    In reply to: [WooCommerce] Sorting

    @pickme
    I found this, but haven’t had a chance to test it yet. Please update here if it works.
    https://wordpress.stackexchange.com/questions/104537/woocommerce-filter-by-featured-products-in-admin

    Thread Starter Jason Wong

    (@eljkmw)

    @jlundie @mouli
    I tried out the following snippet, and sadly it didn’t work for sorting the catalog products accordingly to my explanation above.

    add_filter( 'woocommerce_get_catalog_ordering_args', 'wc_custom_get_catalog_ordering_args' );
    function wc_custom_get_catalog_ordering_args( $args ) {
    	$orderby_value = isset( $_GET['orderby'] ) ? woocommerce_clean( $_GET['orderby'] ) : apply_filters( 'woocommerce_default_catalog_orderby', get_option( 'woocommerce_default_catalog_orderby' ) );
    
    	if ( $orderby_value == 'price' ) {
    		$args['orderby'] = array( 'meta_value_num' => 'ASC', 'title' => 'ASC' );
    		$args['meta_key'] = '_price';
        }
    
    	if ( $orderby_value == 'price-desc' ) {
    		$args['orderby'] = array( 'meta_value_num' => 'DESC', 'title' => 'ASC' );
    		$args['meta_key'] = '_price';
        }
    
        return $args;
    }

    This too was in vain.

    add_action( 'woocommerce_product_query', 'wc_custom_product_query' );
    function wc_custom_product_query( $q ) {
    	if ( ! $q->is_main_query() || is_admin() )   return;
    	
    	$orderby_value = $q->get( 'orderby' );
    	if ( $orderby_value == 'price' || $orderby_value == 'price-desc' ) {
    		$q->set( 'orderby', array(
    			'price' => $orderby_value == 'price' ? 'ASC' : 'DESC',
    			'title' => 'ASC'
    		) );
    	}	
    }

    Where am I doing wrong? (><)”

    • This reply was modified 1 year, 1 month ago by Jason Wong. Reason: another snippet added
Viewing 15 replies - 1 through 15 (of 355 total)