JapeNZ
Forum Replies Created
-
Forum: Plugins
In reply to: [Slideshow] Slideshow not displying on Woocommerce shop pageForum: Plugins
In reply to: [Slideshow] Slideshow not displying on Woocommerce shop pageI’ve worked out that the shop page is an ‘archive’ post type where as the other pages that the slideshows work fine on use the page template.
I’m assuming this is why I can’t get it to work on the shop page? Maybe?Forum: Plugins
In reply to: [Slideshow] Slideshow not displying on Woocommerce shop pageHello,
Thanks for getting back to me:)The changelog can be viewed here: Woocommerce Change Log
and there’s more info here: Develop WooCommerceI’m not completely sure how useful this will be, I have very little idea what any of it means to be honest ??
Forum: Plugins
In reply to: [WooCommerce] Category order by SKU shortcode?Okay so I think I’ve managed to come up with a solution.
Rather than set SKU: Descending as default I’ve used the following code to add sku as a shortcode option:
<?php /** * Returns an array of arguments for ordering products based on the selected values * * @access public * @return array */ public function get_catalog_ordering_args( $orderby = '', $order = '' ) { // Get ordering from query string unless defined if ( ! $orderby ) { $orderby_value = isset( $_GET['orderby'] ) ? wc_clean( $_GET['orderby'] ) : apply_filters( 'woocommerce_default_catalog_orderby', get_option( 'woocommerce_default_catalog_orderby' ) ); // Get order + orderby args from string $orderby_value = explode( '-', $orderby_value ); $orderby = esc_attr( $orderby_value[0] ); $order = ! empty( $orderby_value[1] ) ? $orderby_value[1] : $order; } $orderby = strtolower( $orderby ); $order = strtoupper( $order ); $args = array(); // default - menu_order $args['orderby'] = 'menu_order title'; $args['order'] = $order == 'DESC' ? 'DESC' : 'ASC'; $args['meta_key'] = ''; switch ( $orderby ) { case 'rand' : $args['orderby'] = 'rand'; break; case 'date' : $args['orderby'] = 'date'; $args['order'] = $order == 'ASC' ? 'ASC' : 'DESC'; break; case 'price' : $args['orderby'] = 'meta_value_num'; $args['order'] = $order == 'DESC' ? 'DESC' : 'ASC'; $args['meta_key'] = '_price'; break; case 'popularity' : $args['meta_key'] = 'total_sales'; // Sorting handled later though a hook add_filter( 'posts_clauses', array( $this, 'order_by_popularity_post_clauses' ) ); break; case 'rating' : // Sorting handled later though a hook add_filter( 'posts_clauses', array( $this, 'order_by_rating_post_clauses' ) ); break; case 'title' : $args['orderby'] = 'title'; $args['order'] = $order == 'DESC' ? 'DESC' : 'ASC'; break; case 'sku' : $args['orderby'] = 'meta_value'; $args['order'] = $order == 'DESC' ? 'DESC' : 'ASC'; $args['meta_key'] = '_sku'; break; } return apply_filters( 'woocommerce_get_catalog_ordering_args', $args ); }
I copied the majority of this from woocommerce / includes / class-wc-shortcodes.php and added:
case 'sku' : $args['orderby'] = 'meta_value'; $args['order'] = $order == 'DESC' ? 'DESC' : 'ASC'; $args['meta_key'] = '_sku'; break;
to the list.
The result being I can now add use “sku” as orderby= in product category shortcodes… sweet! Haha!
[product_category category="x-men-vol-4" per_page="99" columns="5" orderby="sku" order="desc" meta_key=""]
You need to create a new file called class-wc-query.php in your child theme:
public_html/wp-content/themes/’your child theme’/woocommerce/includes
and then paste the code in there.
Forum: Plugins
In reply to: [WooCommerce] Category order by SKU shortcode?So I can set Default Product Sorting to ‘SKU: Descending’ using this code:
add_filter( 'woocommerce_get_catalog_ordering_args', 'custom_woocommerce_get_catalog_ordering_args' ); function custom_woocommerce_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 ( 'sku_desc' == $orderby_value ) { $args['orderby'] = 'meta_value'; $args['order'] = 'desc'; $args['meta_key'] = '_sku'; } return $args; } add_filter( 'woocommerce_default_catalog_orderby_options', 'custom_woocommerce_catalog_orderby' ); add_filter( 'woocommerce_catalog_orderby', 'custom_woocommerce_catalog_orderby' ); function custom_woocommerce_catalog_orderby( $sortby ) { $sortby['sku_desc'] = 'SKU: Descending'; return $sortby; }
But this stops the shortcodes I have on some pages using ‘title’, ‘date’ and ‘rand’ from working?!
[product_category category="xmenv2" per_page="99" columns="5" orderby="date" order="desc" meta_key=""]
Is there some code I can add to ‘SKU: Descending’ that will allow custom ordering so I can have ‘custom ordering + SKU: Descending’ as an alternative to ‘default sorting (custom ordering + name)’?
Any help would be very much appreciated:)