Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /************* Add sorting by attributes **************/
- /**
- * Defines the criteria for sorting with options defined in the method below
- */
- add_filter('woocommerce_get_catalog_ordering_args', 'custom_woocommerce_get_catalog_ordering_args');
- function custom_woocommerce_get_catalog_ordering_args( $args ) {
- global $wp_query;
- // Changed the $_SESSION to $_GET
- if (isset($_GET['orderby'])) {
- switch ($_GET['orderby']) :
- case 'velikost1' :
- $args['order'] = 'ASC';
- $args['meta_key'] = 'velikost';
- $args['orderby'] = 'meta_value_num';
- break;
- case 'velikost2' :
- $args['order'] = 'DESC';
- $args['meta_key'] = 'velikost';
- $args['orderby'] = 'meta_value_num';
- break;
- endswitch;
- }
- return $args;
- }
- /**
- * Adds the sorting options to dropdown list .. The logic/criteria is in the method above
- */
- add_filter('woocommerce_catalog_orderby', 'custom_woocommerce_catalog_orderby');
- function custom_woocommerce_catalog_orderby( $sortby ) {
- $sortby['velikost_1'] = 'Seřadit podle velikosti 1';
- $sortby['velikost_2'] = 'Seřadit podle velikosti 2';
- return $sortby;
- }
- /**
- * Save custom attributes as post's meta data as well so that we can use in sorting and searching
- */
- add_action( 'save_post', 'save_woocommerce_attr_to_meta' );
- function save_woocommerce_attr_to_meta( $post_id ) {
- // Get the attribute_names .. For each element get the index and the name of the attribute
- // Then use the index to get the corresponding submitted value from the attribute_values array.
- foreach( $_REQUEST['attribute_names'] as $index => $value ) {
- update_post_meta( $post_id, $value, $_REQUEST['attribute_values'][$index] );
- }
- }
- /************ End of Sorting ***************************/
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement