WooCommerce sort products by the actual product width(not the shipping width)

The Below code works for simple products but fails for products with variance add_filter( ‘woocommerce_get_catalog_ordering_args’, ‘sort_by_width_woocommerce_shop’ ); function sort_by_width_woocommerce_shop( $args ) { global $wp_query; $orderby_value = isset( $_GET[‘orderby’] ) ? wc_clean( (string) wp_unslash( $_GET[‘orderby’] ) ) : wc_clean( get_query_var( ‘orderby’ ) ); if ( ‘width-asc’ == $orderby_value ) { $args[‘orderby’] = ‘meta_value_num’; $args[‘order’] = ‘ASC’; … Read more

WP_Error on attribute + term insert

Try to reregister taxonomies $args = array( ‘name’ => “Color”, ‘slug’ => “color”, ‘order_by’ => “menu_order”, ‘has_archives’ => “”, ); wc_create_attribute($args); WC_Post_Types::register_taxonomies(); $add = wp_insert_term( “Blue”, ‘pa_color’, array( ‘slug’ => “blue” ) ); print_r($add);