Changeset 2822347
- Timestamp:
- 11/22/2022 06:09:41 PM (3 years ago)
- Location:
- woo-shipping-class-filter/trunk
- Files:
-
- 2 edited
-
readme.txt (modified) (2 diffs)
-
woo-shipping-class-filter.php (modified) (5 diffs)
Legend:
- Unmodified
- Added
- Removed
-
woo-shipping-class-filter/trunk/readme.txt
r1941853 r2822347 7 7 Requires at least: 3 8 8 Requires PHP: 5.5 9 Tested up to: 4.9.89 Tested up to: 6.1 10 10 Stable tag: trunk 11 Version: 1.011 Version: 2.0 12 12 13 13 A WooCommerce Extension that enabled filtering products by Shipping class in the admin panel. … … 22 22 23 23 == Screenshots == 24 1. The new filter added to the WooCommerce Products table25 2. The WooCommerce Products table, after installing the plugin (notice the new column on the right)24 1. The WooCommerce Products table, after installing the plugin (notice the new column on the right) 25 2. The new filter added to the WooCommerce Products table 26 26 27 27 == Changelog == 28 29 2.0 - Added orders functionality, allowing you to filter orders by their shipping method 30 31 1.1 - Removed "no shipping class" option (not working in new WC) and changed the old woocommerce_product_filters hook to the new woocommerce_products_admin_list_table_filters 32 28 33 1.0 - First full version of this plugin -
woo-shipping-class-filter/trunk/woo-shipping-class-filter.php
r1941841 r2822347 4 4 * Plugin URI: http://wordpress.org/plugins/woo-shipping-class-filter 5 5 * Description: A WooCommerce Extension that enabled filtering products by Shipping class in the admin panel. 6 * Version: 1.06 * Version: 2.0 7 7 * Author: Reuven Karasik 8 8 * Author URI: http://reuven.karasik.org/ … … 17 17 */ 18 18 add_filter( 'manage_product_posts_columns', 'rk_product_add_shipping_class_column' ); 19 add_ filter( 'manage_product_posts_custom_column', 'rk_product_manage_shipping_class_column', 10, 2 );19 add_action( 'manage_product_posts_custom_column', 'rk_product_manage_shipping_class_column', 10, 2 ); 20 20 21 21 /** … … 52 52 */ 53 53 function rk_product_manage_shipping_class_column( $column_name, $post_id ) { 54 if ( 'shipping_class' === $column_name ) {55 $product = new WC_Product( $post_id );56 $class_slug = $product->get_shipping_class();57 if ( $class_slug ) { 58 $term = get_term_by( 'slug', $class_slug, 'product_shipping_class');59 echo esc_html( $term->name);60 return true;61 }62 e sc_html_e( 'No shipping class', 'woocommerce');54 if ( 'shipping_class' !== $column_name ) { 55 return $column_name; 56 } 57 58 $product = new WC_Product( $post_id ); 59 $class_slug = $product->get_shipping_class(); 60 if ( $class_slug ) { 61 $term = get_term_by( 'slug', $class_slug, 'product_shipping_class' ); 62 echo esc_html( $term->name ); 63 63 return true; 64 64 } 65 return $column_name; 65 66 esc_html_e( 'No shipping class', 'woocommerce' ); 67 return true; 66 68 } 67 69 … … 70 72 */ 71 73 72 /* 73 Preparing for WooCommerce 3.5 - introduces a new filter `woocommerce_products_admin_list_table_filters` 74 75 add_filter( 'woocommerce_products_admin_list_table_filters', 'rk_add_shipping_class_filter' ); 76 function rk_add_shipping_class_filter( $filters ) { 77 $filters['shipping_class'] = 'rk_render_products_shipping_class_filter'; 74 add_filter( 'woocommerce_products_admin_list_table_filters', 'rk_add_shipping_class_filter_products' ); 75 function rk_add_shipping_class_filter_products( $filters ) { 76 $filters['shipping_class'] = 'rk_render_shipping_class_filter'; 78 77 return $filters; 79 }80 81 Instead:82 */83 84 add_filter( 'woocommerce_product_filters', 'rk_add_shipping_class_filter' );85 /**86 * Add filter box for Shipping Class87 *88 * @param string $output The previous HTML Output.89 * @return string The HTML Output.90 */91 function rk_add_shipping_class_filter( $output ) {92 ob_start();93 rk_render_products_shipping_class_filter();94 $output .= ob_get_clean();95 return $output;96 78 } 97 79 … … 99 81 * Echoes the shipping class filter select box (copied and modified from Woocommerce source code) 100 82 */ 101 function rk_render_ products_shipping_class_filter() {83 function rk_render_shipping_class_filter($type = 'product') { 102 84 global $woocommerce; 103 $current_shipping_class = isset( $_REQUEST['product_shipping_class'] ) ? wc_clean( wp_unslash( $_REQUEST['product_shipping_class'] ) ) : false; // WPCS: input var ok, sanitization ok. 104 $shipping_classes = array_merge( 105 array( 106 (object) array( 107 'term_id' => '0', 108 'slug' => '0', 109 'name' => __( 'No shipping class', 'woocommerce' ), 110 ), 111 ), 112 $woocommerce->shipping->get_shipping_classes() 113 ); 114 115 $output = '<select name="product_shipping_class"><option value="">' . esc_html__( 'Filter by', 'woocommerce' ) . ' ' . esc_html__( 'Shipping class', 'woocommerce' ) . '</option>'; 116 foreach ( $shipping_classes as $shipping_class ) { 85 $current_shipping_class = isset( $_REQUEST[$type . '_shipping_class'] ) ? wc_clean( wp_unslash( $_REQUEST[$type . '_shipping_class'] ) ) : false; // WPCS: input var ok, sanitization ok. 86 $output = '<select name="' . $type . '_shipping_class"><option value="">' . esc_html__( 'Filter by', 'woocommerce' ) . ' ' . esc_html__( 'Shipping class', 'woocommerce' ) . '</option>'; 87 foreach ( $woocommerce->shipping->get_shipping_classes() as $shipping_class ) { 117 88 $slug = $shipping_class->slug; 118 89 $name = $shipping_class->name; 119 90 $output .= '<option ' . selected( $slug, $current_shipping_class, false ) . ' value="' . esc_attr( $slug ) . '">' . esc_html( $name ) . '</option>'; 120 91 } 121 $output .= '</select>';122 echo $output; // WPCS: XSS ok.92 $output .= '</select>'; 93 echo $output; // WPCS: XSS ok. 123 94 } 124 95 96 include( plugin_dir_path( __FILE__ ) . 'orders.php');
Note: See TracChangeset
for help on using the changeset viewer.