'title', 'id' => 'aisp_otools_other_section', 'title' => __( 'Other Tools', 'aisp-order-tools-for-woocommerce' ), 'desc' => __( 'Optional utilities that enhance WooCommerce usability and admin productivity.', 'aisp-order-tools-for-woocommerce' ), ], [ 'title' => __( 'Show product SKU on cart page', 'aisp-order-tools-for-woocommerce' ), 'desc' => __( 'Displays each product SKU directly below the item name on the cart page for easier reference.', 'aisp-order-tools-for-woocommerce' ), 'id' => 'aisp_otools_display_sku_cart', 'default' => 'no', 'type' => 'checkbox', ], [ 'title' => __( 'Add "Empty Cart" button', 'aisp-order-tools-for-woocommerce' ), 'desc' => __( 'Adds a quick-access button allowing customers to empty their entire cart in one click.', 'aisp-order-tools-for-woocommerce' ), 'id' => 'aisp_otools_clear_cart_button', 'default' => 'no', 'type' => 'checkbox', ], [ 'title' => __( 'Add company column', 'aisp-order-tools-for-woocommerce' ), 'desc' => __( 'Add company column in the WooCommerce admin order list and WordPress user list.
Add searchable field by company name and phone number in WordPress user list', 'aisp-order-tools-for-woocommerce' ), 'id' => 'aisp_otools_add_name_company', 'default' => 'no', 'type' => 'checkbox', ], [ 'title' => __( 'Sort users by registration date', 'aisp-order-tools-for-woocommerce' ), 'desc' => __( 'Automatically sorts the user list from newest to oldest registered. ', 'aisp-order-tools-for-woocommerce' ), 'id' => 'aisp_otools_sort_user', 'default' => 'no', 'type' => 'checkbox', ], [ 'title' => __( 'Show "View on Google Maps" on order page', 'aisp-order-tools-for-woocommerce' ), 'desc' => __( 'Displays a Google Maps link below the billing address in admin order pages.', 'aisp-order-tools-for-woocommerce' ), 'id' => 'aisp_otools_admin_maps_link', 'default' => 'no', 'type' => 'checkbox', ], [ 'title' => __( 'Show "View customer orders" button on user profile', 'aisp-order-tools-for-woocommerce' ), 'desc' => __( 'Adds a button in user profile page to quickly access all orders linked to that account', 'aisp-order-tools-for-woocommerce' ), 'id' => 'aisp_otools_customer_orders_button', 'default' => 'no', 'type' => 'checkbox', ], [ 'type' => 'sectionend', 'id' => 'aisp_otools_other_section', ], ]; return apply_filters( 'aisp_otools_other_tools_settings', $settings ); } public static function enable_display_sku_cart() { if ( 'yes' !== get_option( 'aisp_otools_display_sku_cart', 'no' ) ) { return; } add_action( 'woocommerce_after_cart_item_name', function( $cart_item ) { $product = $cart_item['data']; if ( $product && $product->get_sku() ) { echo '
SKU: ' . esc_html( $product->get_sku() ) . '
'; } }, 10, 1 ); } public static function enable_clear_cart_button() { if ( 'yes' !== get_option( 'aisp_otools_clear_cart_button', 'no' ) ) { return; } add_action( 'woocommerce_cart_actions', function() { wp_nonce_field( 'aisp_empty_cart_action', 'aisp_empty_cart_nonce' ); echo ''; } ); add_action( 'wp_loaded', function() { if ( empty( $_POST['aisp_empty_cart'] ) ) { return; } if ( isset( $_POST['aisp_empty_cart_nonce'] ) && wp_verify_nonce( sanitize_text_field( wp_unslash( $_POST['aisp_empty_cart_nonce'] ) ), 'aisp_empty_cart_action' ) ) { WC()->cart->empty_cart(); wp_safe_redirect( wc_get_cart_url() ); exit; } } ); } public static function enable_add_name_company() { if ( 'yes' !== get_option( 'aisp_otools_add_name_company', 'no' ) ) { return; } // WooCommerce HPOS order list column. add_filter( 'woocommerce_shop_order_list_table_columns', function( $columns ) { $new_columns = []; foreach ( $columns as $key => $label ) { $new_columns[ $key ] = $label; if ( $key === 'order_number' || $key === 'billing_address' ) { $new_columns['billing_company'] = __( 'Company', 'aisp-order-tools-for-woocommerce' ); } } if ( ! isset( $new_columns['billing_company'] ) ) { $new_columns['billing_company'] = __( 'Company', 'aisp-order-tools-for-woocommerce' ); } return $new_columns; } ); add_action( 'woocommerce_shop_order_list_table_custom_column', function( $column_name, $order ) { if ( 'billing_company' !== $column_name ) { return; } $company = trim( $order->get_billing_company() ); echo $company ? esc_html( $company ) : '—'; }, 10, 2 ); // Legacy CPT order list column. add_filter( 'manage_shop_order_posts_columns', function( $columns ) { $new_columns = []; foreach ( $columns as $key => $label ) { $new_columns[ $key ] = $label; if ( $key === 'order_number' || $key === 'billing_address' ) { $new_columns['billing_company'] = __( 'Company', 'aisp-order-tools-for-woocommerce' ); } } if ( ! isset( $new_columns['billing_company'] ) ) { $new_columns['billing_company'] = __( 'Company', 'aisp-order-tools-for-woocommerce' ); } return $new_columns; } ); add_action( 'manage_shop_order_posts_custom_column', function( $column, $post_id ) { if ( 'billing_company' !== $column ) { return; } $order = wc_get_order( $post_id ); $company = $order ? trim( $order->get_billing_company() ) : ''; echo $company ? esc_html( $company ) : '—'; }, 10, 2 ); // WooCommerce customer list column. add_filter( 'woocommerce_customer_list_table_columns', function( $columns ) { $new_columns = []; foreach ( $columns as $key => $label ) { $new_columns[ $key ] = $label; if ( $key === 'name' ) { $new_columns['billing_company'] = __( 'Company', 'aisp-order-tools-for-woocommerce' ); } } return $new_columns; } ); // WordPress users list column. add_filter( 'manage_users_columns', function( $columns ) { $new_columns = []; foreach ( $columns as $key => $label ) { $new_columns[ $key ] = $label; if ( $key === 'name' ) { $new_columns['billing_company'] = __( 'Company', 'aisp-order-tools-for-woocommerce' ); } } return $new_columns; } ); add_action( 'manage_users_custom_column', function( $value, $column_name, $user_id ) { if ( $column_name !== 'billing_company' ) { return $value; } $company = trim( get_user_meta( $user_id, 'billing_company', true ) ); return $company ? esc_html( $company ) : '—'; }, 10, 3 ); // Extend user search to company name and phone. add_action( 'pre_user_query', function( $query ) { global $wpdb; if ( ! is_admin() || empty( $query->query_vars['search'] ) || ! isset( $query->query_vars['search_columns'] ) ) { return; } $search = trim( str_replace( '*', '', $query->query_vars['search'] ) ); if ( empty( $search ) ) { return; } $like = '%' . $wpdb->esc_like( $search ) . '%'; $query->query_from .= " LEFT JOIN {$wpdb->usermeta} AS um_company ON ({$wpdb->users}.ID = um_company.user_id AND um_company.meta_key = 'billing_company') LEFT JOIN {$wpdb->usermeta} AS um_phone ON ({$wpdb->users}.ID = um_phone.user_id AND um_phone.meta_key = 'billing_phone') "; $query->query_where .= $wpdb->prepare( " OR um_company.meta_value LIKE %s OR um_phone.meta_value LIKE %s ", $like, $like ); } ); } public static function enable_admin_maps_link() { if ( 'yes' !== get_option( 'aisp_otools_admin_maps_link', 'no' ) ) { return; } add_action( 'woocommerce_admin_order_data_after_billing_address', function( $order ) { $address = rawurlencode( $order->get_billing_address_1() . ' ' . $order->get_billing_city() . ' ' . $order->get_billing_postcode() . ' ' . $order->get_billing_country() ); echo '

📍 ' . esc_html__( 'View on Google Maps', 'aisp-order-tools-for-woocommerce' ) . '

'; } ); } public static function enable_sort_user_by_registration_date() { if ( 'yes' !== get_option( 'aisp_otools_sort_user', 'no' ) ) { return; } add_filter( 'manage_users_columns', function( $columns ) { $columns['registration_date'] = __( 'Registration date', 'aisp-order-tools-for-woocommerce' ); return $columns; } ); add_filter( 'manage_users_custom_column', function( $value, $column_name, $user_id ) { if ( 'registration_date' !== $column_name ) { return $value; } $user = get_userdata( $user_id ); if ( ! $user || empty( $user->user_registered ) ) { return '—'; } return date_i18n( get_option( 'date_format' ), strtotime( $user->user_registered ) ); }, 10, 3 ); add_filter( 'manage_users_sortable_columns', function( $columns ) { $columns['registration_date'] = 'registered'; return $columns; } ); add_filter( 'users_list_table_query_args', function( $args ) { if ( empty( $args['orderby'] ) ) { $args['orderby'] = 'registered'; $args['order'] = 'DESC'; } if ( isset( $args['orderby'] ) && 'registered' === $args['orderby'] ) { $args['orderby'] = 'user_registered'; } return $args; } ); } public static function enable_customer_orders_button() { if ( 'yes' !== get_option( 'aisp_otools_customer_orders_button', 'no' ) ) { return; } add_action( 'personal_options', function( $user ) { if ( ! current_user_can( 'manage_woocommerce' ) ) { return; } $user_id = (int) $user->ID; if ( ! $user_id ) { return; } $hpos_enabled = false; if ( class_exists( '\Automattic\WooCommerce\Utilities\OrderUtil' ) ) { $hpos_enabled = \Automattic\WooCommerce\Utilities\OrderUtil::custom_orders_table_usage_is_enabled(); } if ( $hpos_enabled ) { $orders_url = add_query_arg( [ 'page' => 'wc-orders', '_customer_user' => $user_id, 'orderby' => 'date', 'order' => 'desc', ], admin_url( 'admin.php' ) ); } else { $orders_url = add_query_arg( [ 'post_type' => 'shop_order', '_customer_user' => $user_id, 'orderby' => 'date', 'order' => 'desc', ], admin_url( 'edit.php' ) ); } $cache_key = 'aisp_order_count_' . $user_id; $order_count = wp_cache_get( $cache_key, 'aisp_otools' ); if ( false === $order_count ) { $query = wc_get_orders( [ 'customer_id' => $user_id, 'limit' => 1, 'return' => 'ids', 'paginate' => true, ] ); $order_count = isset( $query->total ) ? (int) $query->total : 0; wp_cache_set( $cache_key, $order_count, 'aisp_otools', 300 ); } $has_orders = $order_count > 0; $label = $has_orders /* translators: %d: number of orders */ ? sprintf( _n( 'View orders (%d)', 'View orders (%d)', $order_count, 'aisp-order-tools-for-woocommerce' ), $order_count ) : __( 'View orders (0)', 'aisp-order-tools-for-woocommerce' ); echo ''; echo ''; echo ''; if ( $has_orders ) { echo ''; echo esc_html( $label ); echo ''; } else { echo ''; echo esc_html( $label ); echo ''; } echo ''; echo ''; } ); } } add_action( 'plugins_loaded', function() { AISP_Settings_OtherTools::enable_display_sku_cart(); AISP_Settings_OtherTools::enable_clear_cart_button(); AISP_Settings_OtherTools::enable_add_name_company(); AISP_Settings_OtherTools::enable_admin_maps_link(); AISP_Settings_OtherTools::enable_sort_user_by_registration_date(); AISP_Settings_OtherTools::enable_customer_orders_button(); new Floating_Panel(); } );