Plugin Directory

Changeset 2822347


Ignore:
Timestamp:
11/22/2022 06:09:41 PM (3 years ago)
Author:
kinging
Message:

Version 2.0 - orders

Location:
woo-shipping-class-filter/trunk
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • woo-shipping-class-filter/trunk/readme.txt

    r1941853 r2822347  
    77Requires at least: 3
    88Requires PHP: 5.5
    9 Tested up to: 4.9.8
     9Tested up to: 6.1
    1010Stable tag: trunk
    11 Version: 1.0
     11Version: 2.0
    1212
    1313A WooCommerce Extension that enabled filtering products by Shipping class in the admin panel.
     
    2222
    2323== Screenshots ==
    24 1. The new filter added to the WooCommerce Products table
    25 2. The WooCommerce Products table, after installing the plugin (notice the new column on the right)
     241. The WooCommerce Products table, after installing the plugin (notice the new column on the right)
     252. The new filter added to the WooCommerce Products table
    2626
    2727== Changelog ==
     28
     292.0 - Added orders functionality, allowing you to filter orders by their shipping method
     30
     311.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
    28331.0 - First full version of this plugin
  • woo-shipping-class-filter/trunk/woo-shipping-class-filter.php

    r1941841 r2822347  
    44 * Plugin URI: http://wordpress.org/plugins/woo-shipping-class-filter
    55 * Description: A WooCommerce Extension that enabled filtering products by Shipping class in the admin panel.
    6  * Version: 1.0
     6 * Version: 2.0
    77 * Author: Reuven Karasik
    88 * Author URI: http://reuven.karasik.org/
     
    1717 */
    1818add_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 );
     19add_action( 'manage_product_posts_custom_column', 'rk_product_manage_shipping_class_column', 10, 2 );
    2020
    2121/**
     
    5252 */
    5353function 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         esc_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 );
    6363        return true;
    6464    }
    65     return $column_name;
     65
     66    esc_html_e( 'No shipping class', 'woocommerce' );
     67    return true;
    6668}
    6769
     
    7072 */
    7173
    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';
     74add_filter( 'woocommerce_products_admin_list_table_filters', 'rk_add_shipping_class_filter_products' );
     75function rk_add_shipping_class_filter_products( $filters ) {
     76    $filters['shipping_class'] = 'rk_render_shipping_class_filter';
    7877    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 Class
    87  *
    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;
    9678}
    9779
     
    9981 * Echoes the shipping class filter select box (copied and modified from Woocommerce source code)
    10082 */
    101 function rk_render_products_shipping_class_filter() {
     83function rk_render_shipping_class_filter($type = 'product') {
    10284    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 ) {
    11788        $slug = $shipping_class->slug;
    11889        $name = $shipping_class->name;
    11990        $output .= '<option ' . selected( $slug, $current_shipping_class, false ) . ' value="' . esc_attr( $slug ) . '">' . esc_html( $name ) . '</option>';
    12091    }
    121         $output .= '</select>';
    122         echo $output; // WPCS: XSS ok.
     92    $output .= '</select>';
     93    echo $output; // WPCS: XSS ok.
    12394}
    12495
     96include( plugin_dir_path( __FILE__ ) . 'orders.php');
Note: See TracChangeset for help on using the changeset viewer.