• Resolved moonfolk

    (@moonfolk)


    I have this code in my functions.php which displays Shipping Zone Name for all orders in the Admin Order Dashboard – refer screenshot https://ibb.co/GWqLgxF

    // Add column display for shipping zone data on Admin Orders Dashboard
    // 
    // Add a Header
    function filter_manage_edit_shop_order_columns( $columns ) {
        // Add new column
        $columns['shipping_zone'] = 'Shipping zone';
    
        return $columns;
    }
    add_filter( 'manage_edit-shop_order_columns', 'filter_manage_edit_shop_order_columns', 10, 1 );
    
    // Populate the Column
    function action_manage_shop_order_posts_custom_column( $column, $post_id ) {
        // Compare
        if ( $column == 'shipping_zone' ) {
            // Get order
            $order = wc_get_order( $post_id );
    
            // Iterating through order shipping items
            foreach( $order->get_items( 'shipping' ) as $item_id => $shipping_item_obj ) {
                $shipping_method_instance_id = $shipping_item_obj->get_instance_id(); // The instance ID
            }
            
            // Get zone by instance id
            $shipping_zone = WC_Shipping_Zones::get_zone_by( 'instance_id', $shipping_method_instance_id );
            
            // Get zone name
            $current_zone_name = $shipping_zone->get_zone_name();
            
            if ( ! empty ( $current_zone_name ) ) {
                echo $current_zone_name;    
            }
        }
    }
    add_action( 'manage_shop_order_posts_custom_column' , 'action_manage_shop_order_posts_custom_column', 10, 2 );
    

    For orders that qualified for free shipping, it goes through the Advanced Free Shipping plugin (which is a great plugin!). And all orders that goes through this plugin somehow does not have the Shipping Zone Name.

    I’m curious to know how can I make the plugin generate and store the Shipping Zone Name, so that i can create a filter

Viewing 1 replies (of 1 total)
  • Plugin Author Jeroen Sormani

    (@sormano)

    Hi,

    The rates from this plugin are not setup within the WC Zones, so they don’t have a (zone) instance ID assigned.

    You can consider using the Advanced Shipping?plugin instead as that does allow for setting up rates within the WC Zones.

    Cheers,
    Jeroen

Viewing 1 replies (of 1 total)
  • The topic ‘Why is the shipping zone data not generated/used by plugin?’ is closed to new replies.