/wp-content/plugins/woocommerce/includes/admin/class-wc-admin-post-types.php
PHP | 2091 lines | 1426 code | 353 blank | 312 comment | 320 complexity | 9830b8c0b9acf16e316569647256b7ba MD5 | raw file
Possible License(s): LGPL-3.0, Apache-2.0
Large files files are truncated, but you can click here to view the full file
- <?php
- /**
- * Post Types Admin
- *
- * @author WooThemes
- * @category Admin
- * @package WooCommerce/Admin
- * @version 2.1.0
- */
- if ( ! defined( 'ABSPATH' ) ) {
- exit; // Exit if accessed directly
- }
- if ( ! class_exists( 'WC_Admin_Post_Types' ) ) :
- /**
- * WC_Admin_Post_Types Class
- *
- * Handles the edit posts views and some functionality on the edit post screen for WC post types.
- */
- class WC_Admin_Post_Types {
- /**
- * Constructor
- */
- public function __construct() {
- add_filter( 'post_updated_messages', array( $this, 'post_updated_messages' ) );
- add_action( 'admin_print_scripts', array( $this, 'disable_autosave' ) );
- // WP List table columns. Defined here so they are always available for events such as inline editing.
- add_filter( 'manage_edit-product_columns', array( $this, 'product_columns' ) );
- add_filter( 'manage_edit-shop_coupon_columns', array( $this, 'shop_coupon_columns' ) );
- add_filter( 'manage_edit-shop_order_columns', array( $this, 'shop_order_columns' ) );
- add_action( 'manage_product_posts_custom_column', array( $this, 'render_product_columns' ), 2 );
- add_action( 'manage_shop_coupon_posts_custom_column', array( $this, 'render_shop_coupon_columns' ), 2 );
- add_action( 'manage_shop_order_posts_custom_column', array( $this, 'render_shop_order_columns' ), 2 );
- add_filter( 'manage_edit-product_sortable_columns', array( $this, 'product_sortable_columns' ) );
- add_filter( 'manage_edit-shop_coupon_sortable_columns', array( $this, 'shop_coupon_sortable_columns' ) );
- add_filter( 'manage_edit-shop_order_sortable_columns', array( $this, 'shop_order_sortable_columns' ) );
- add_filter( 'bulk_actions-edit-shop_order', array( $this, 'shop_order_bulk_actions' ) );
- add_filter( 'views_edit-product', array( $this, 'product_sorting_link' ) );
- // Bulk / quick edit
- add_action( 'bulk_edit_custom_box', array( $this, 'bulk_edit' ), 10, 2 );
- add_action( 'quick_edit_custom_box', array( $this, 'quick_edit' ), 10, 2 );
- add_action( 'save_post', array( $this, 'bulk_and_quick_edit_save_post' ), 10, 2 );
- add_action( 'admin_footer', array( $this, 'bulk_admin_footer' ), 10 );
- add_action( 'load-edit.php', array( $this, 'bulk_action' ) );
- add_action( 'admin_notices', array( $this, 'bulk_admin_notices' ) );
- // Order Search
- add_filter( 'get_search_query', array( $this, 'shop_order_search_label' ) );
- add_filter( 'query_vars', array( $this, 'add_custom_query_var' ) );
- add_action( 'parse_query', array( $this, 'shop_order_search_custom_fields' ) );
- // Filters
- add_action( 'restrict_manage_posts', array( $this, 'restrict_manage_posts' ) );
- add_filter( 'request', array( $this, 'request_query' ) );
- add_filter( 'parse_query', array( $this, 'product_filters_query' ) );
- add_filter( 'posts_search', array( $this, 'product_search' ) );
- // Status transitions
- add_action( 'delete_post', array( $this, 'delete_post' ) );
- add_action( 'wp_trash_post', array( $this, 'trash_post' ) );
- add_action( 'untrash_post', array( $this, 'untrash_post' ) );
- add_action( 'before_delete_post', array( $this, 'delete_order_items' ) );
- // Edit post screens
- add_filter( 'media_view_strings', array( $this, 'media_view_strings' ), 10, 2 );
- add_filter( 'enter_title_here', array( $this, 'enter_title_here' ), 1, 2 );
- add_action( 'edit_form_after_title', array( $this, 'edit_form_after_title' ) );
- add_filter( 'media_view_strings', array( $this, 'change_insert_into_post' ) );
- add_action( 'post_submitbox_misc_actions', array( $this, 'product_data_visibility' ) );
- $this->change_featured_image_text();
- // Uploads
- add_filter( 'upload_dir', array( $this, 'upload_dir' ) );
- add_action( 'media_upload_downloadable_product', array( $this, 'media_upload_downloadable_product' ) );
- if ( ! function_exists( 'duplicate_post_plugin_activation' ) ) {
- include( 'class-wc-admin-duplicate-product.php' );
- }
- include_once( 'class-wc-admin-meta-boxes.php' );
- // Download permissions
- add_action( 'woocommerce_process_product_file_download_paths', array( $this, 'process_product_file_download_paths' ), 10, 3 );
- }
- /**
- * Define custom columns for products
- * @param array $existing_columns
- * @return array
- */
- public function product_columns( $existing_columns ) {
- if ( empty( $existing_columns ) && ! is_array( $existing_columns ) ) {
- $existing_columns = array();
- }
- unset( $existing_columns['title'], $existing_columns['comments'], $existing_columns['date'] );
- $columns = array();
- $columns['cb'] = '<input type="checkbox" />';
- $columns['thumb'] = '<span class="wc-image tips" data-tip="' . __( 'Image', 'woocommerce' ) . '">' . __( 'Image', 'woocommerce' ) . '</span>';
- $columns['name'] = __( 'Name', 'woocommerce' );
- if ( wc_product_sku_enabled() ) {
- $columns['sku'] = __( 'SKU', 'woocommerce' );
- }
- if ( 'yes' == get_option( 'woocommerce_manage_stock' ) ) {
- $columns['is_in_stock'] = __( 'Stock', 'woocommerce' );
- }
- $columns['price'] = __( 'Price', 'woocommerce' );
- $columns['product_cat'] = __( 'Categories', 'woocommerce' );
- $columns['product_tag'] = __( 'Tags', 'woocommerce' );
- $columns['featured'] = '<span class="wc-featured parent-tips" data-tip="' . __( 'Featured', 'woocommerce' ) . '">' . __( 'Featured', 'woocommerce' ) . '</span>';
- $columns['product_type'] = '<span class="wc-type parent-tips" data-tip="' . __( 'Type', 'woocommerce' ) . '">' . __( 'Type', 'woocommerce' ) . '</span>';
- $columns['date'] = __( 'Date', 'woocommerce' );
- return array_merge( $columns, $existing_columns );
- }
- /**
- * Define custom columns for coupons
- * @param array $existing_columns
- * @return array
- */
- public function shop_coupon_columns( $existing_columns ) {
- $columns = array();
- $columns["cb"] = "<input type=\"checkbox\" />";
- $columns["coupon_code"] = __( 'Code', 'woocommerce' );
- $columns["type"] = __( 'Coupon type', 'woocommerce' );
- $columns["amount"] = __( 'Coupon amount', 'woocommerce' );
- $columns["description"] = __( 'Description', 'woocommerce' );
- $columns["products"] = __( 'Product IDs', 'woocommerce' );
- $columns["usage"] = __( 'Usage / Limit', 'woocommerce' );
- $columns["expiry_date"] = __( 'Expiry date', 'woocommerce' );
- return $columns;
- }
- /**
- * Define custom columns for orders
- * @param array $existing_columns
- * @return array
- */
- public function shop_order_columns( $existing_columns ) {
- $columns = array();
- $columns['cb'] = '<input type="checkbox" />';
- $columns['order_status'] = '<span class="status_head tips" data-tip="' . esc_attr__( 'Status', 'woocommerce' ) . '">' . esc_attr__( 'Status', 'woocommerce' ) . '</span>';
- $columns['order_title'] = __( 'Order', 'woocommerce' );
- $columns['order_items'] = __( 'Purchased', 'woocommerce' );
- $columns['shipping_address'] = __( 'Ship to', 'woocommerce' );
- $columns['customer_message'] = '<span class="notes_head tips" data-tip="' . esc_attr__( 'Customer Message', 'woocommerce' ) . '">' . esc_attr__( 'Customer Message', 'woocommerce' ) . '</span>';
- $columns['order_notes'] = '<span class="order-notes_head tips" data-tip="' . esc_attr__( 'Order Notes', 'woocommerce' ) . '">' . esc_attr__( 'Order Notes', 'woocommerce' ) . '</span>';
- $columns['order_date'] = __( 'Date', 'woocommerce' );
- $columns['order_total'] = __( 'Total', 'woocommerce' );
- $columns['order_actions'] = __( 'Actions', 'woocommerce' );
- return $columns;
- }
- /**
- * Ouput custom columns for products
- * @param string $column
- */
- public function render_product_columns( $column ) {
- global $post;
- if ( empty( $the_product ) || $the_product->id != $post->ID ) {
- $the_product = wc_get_product( $post );
- }
- switch ( $column ) {
- case 'thumb' :
- echo '<a href="' . get_edit_post_link( $post->ID ) . '">' . $the_product->get_image() . '</a>';
- break;
- case 'name' :
- $edit_link = get_edit_post_link( $post->ID );
- $title = _draft_or_post_title();
- $post_type_object = get_post_type_object( $post->post_type );
- $can_edit_post = current_user_can( $post_type_object->cap->edit_post, $post->ID );
- echo '<strong><a class="row-title" href="' . esc_url( $edit_link ) .'">' . $title.'</a>';
- _post_states( $post );
- echo '</strong>';
- if ( $post->post_parent > 0 ) {
- echo ' ← <a href="'. get_edit_post_link( $post->post_parent ) .'">'. get_the_title( $post->post_parent ) .'</a>';
- }
- // Excerpt view
- if ( isset( $_GET['mode'] ) && 'excerpt' == $_GET['mode'] ) {
- echo apply_filters( 'the_excerpt', $post->post_excerpt );
- }
- // Get actions
- $actions = array();
- $actions['id'] = 'ID: ' . $post->ID;
- if ( $can_edit_post && 'trash' != $post->post_status ) {
- $actions['edit'] = '<a href="' . get_edit_post_link( $post->ID, true ) . '" title="' . esc_attr( __( 'Edit this item', 'woocommerce' ) ) . '">' . __( 'Edit', 'woocommerce' ) . '</a>';
- $actions['inline hide-if-no-js'] = '<a href="#" class="editinline" title="' . esc_attr( __( 'Edit this item inline', 'woocommerce' ) ) . '">' . __( 'Quick Edit', 'woocommerce' ) . '</a>';
- }
- if ( current_user_can( $post_type_object->cap->delete_post, $post->ID ) ) {
- if ( 'trash' == $post->post_status ) {
- $actions['untrash'] = '<a title="' . esc_attr( __( 'Restore this item from the Trash', 'woocommerce' ) ) . '" href="' . wp_nonce_url( admin_url( sprintf( $post_type_object->_edit_link . '&action=untrash', $post->ID ) ), 'untrash-post_' . $post->ID ) . '">' . __( 'Restore', 'woocommerce' ) . '</a>';
- } elseif ( EMPTY_TRASH_DAYS ) {
- $actions['trash'] = '<a class="submitdelete" title="' . esc_attr( __( 'Move this item to the Trash', 'woocommerce' ) ) . '" href="' . get_delete_post_link( $post->ID ) . '">' . __( 'Trash', 'woocommerce' ) . '</a>';
- }
- if ( 'trash' == $post->post_status || ! EMPTY_TRASH_DAYS ) {
- $actions['delete'] = '<a class="submitdelete" title="' . esc_attr( __( 'Delete this item permanently', 'woocommerce' ) ) . '" href="' . get_delete_post_link( $post->ID, '', true ) . '">' . __( 'Delete Permanently', 'woocommerce' ) . '</a>';
- }
- }
- if ( $post_type_object->public ) {
- if ( in_array( $post->post_status, array( 'pending', 'draft', 'future' ) ) ) {
- if ( $can_edit_post )
- $actions['view'] = '<a href="' . esc_url( add_query_arg( 'preview', 'true', get_permalink( $post->ID ) ) ) . '" title="' . esc_attr( sprintf( __( 'Preview “%s”', 'woocommerce' ), $title ) ) . '" rel="permalink">' . __( 'Preview', 'woocommerce' ) . '</a>';
- } elseif ( 'trash' != $post->post_status ) {
- $actions['view'] = '<a href="' . get_permalink( $post->ID ) . '" title="' . esc_attr( sprintf( __( 'View “%s”', 'woocommerce' ), $title ) ) . '" rel="permalink">' . __( 'View', 'woocommerce' ) . '</a>';
- }
- }
- $actions = apply_filters( 'post_row_actions', $actions, $post );
- echo '<div class="row-actions">';
- $i = 0;
- $action_count = sizeof($actions);
- foreach ( $actions as $action => $link ) {
- ++$i;
- ( $i == $action_count ) ? $sep = '' : $sep = ' | ';
- echo '<span class="' . $action . '">' . $link . $sep . '</span>';
- }
- echo '</div>';
- get_inline_data( $post );
- /* Custom inline data for woocommerce */
- echo '
- <div class="hidden" id="woocommerce_inline_' . $post->ID . '">
- <div class="menu_order">' . $post->menu_order . '</div>
- <div class="sku">' . $the_product->sku . '</div>
- <div class="regular_price">' . $the_product->regular_price . '</div>
- <div class="sale_price">' . $the_product->sale_price . '</div>
- <div class="weight">' . $the_product->weight . '</div>
- <div class="length">' . $the_product->length . '</div>
- <div class="width">' . $the_product->width . '</div>
- <div class="height">' . $the_product->height . '</div>
- <div class="visibility">' . $the_product->visibility . '</div>
- <div class="stock_status">' . $the_product->stock_status . '</div>
- <div class="stock">' . $the_product->stock . '</div>
- <div class="manage_stock">' . $the_product->manage_stock . '</div>
- <div class="featured">' . $the_product->featured . '</div>
- <div class="product_type">' . $the_product->product_type . '</div>
- <div class="product_is_virtual">' . $the_product->virtual . '</div>
- <div class="tax_status">' . $the_product->tax_status . '</div>
- <div class="tax_class">' . $the_product->tax_class . '</div>
- <div class="backorders">' . $the_product->backorders . '</div>
- </div>
- ';
- break;
- case 'sku' :
- echo $the_product->get_sku() ? $the_product->get_sku() : '<span class="na">–</span>';
- break;
- case 'product_type' :
- if ( 'grouped' == $the_product->product_type ) {
- echo '<span class="product-type tips grouped" data-tip="' . __( 'Grouped', 'woocommerce' ) . '"></span>';
- } elseif ( 'external' == $the_product->product_type ) {
- echo '<span class="product-type tips external" data-tip="' . __( 'External/Affiliate', 'woocommerce' ) . '"></span>';
- } elseif ( 'simple' == $the_product->product_type ) {
- if ( $the_product->is_virtual() ) {
- echo '<span class="product-type tips virtual" data-tip="' . __( 'Virtual', 'woocommerce' ) . '"></span>';
- } elseif ( $the_product->is_downloadable() ) {
- echo '<span class="product-type tips downloadable" data-tip="' . __( 'Downloadable', 'woocommerce' ) . '"></span>';
- } else {
- echo '<span class="product-type tips simple" data-tip="' . __( 'Simple', 'woocommerce' ) . '"></span>';
- }
- } elseif ( 'variable' == $the_product->product_type ) {
- echo '<span class="product-type tips variable" data-tip="' . __( 'Variable', 'woocommerce' ) . '"></span>';
- } else {
- // Assuming that we have other types in future
- echo '<span class="product-type tips ' . $the_product->product_type . '" data-tip="' . ucfirst( $the_product->product_type ) . '"></span>';
- }
- break;
- case 'price' :
- echo $the_product->get_price_html() ? $the_product->get_price_html() : '<span class="na">–</span>';
- break;
- case 'product_cat' :
- case 'product_tag' :
- if ( ! $terms = get_the_terms( $post->ID, $column ) ) {
- echo '<span class="na">–</span>';
- } else {
- foreach ( $terms as $term ) {
- $termlist[] = '<a href="' . admin_url( 'edit.php?' . $column . '=' . $term->slug . '&post_type=product' ) . ' ">' . $term->name . '</a>';
- }
- echo implode( ', ', $termlist );
- }
- break;
- case 'featured' :
- $url = wp_nonce_url( admin_url( 'admin-ajax.php?action=woocommerce_feature_product&product_id=' . $post->ID ), 'woocommerce-feature-product' );
- echo '<a href="' . esc_url( $url ) . '" title="'. __( 'Toggle featured', 'woocommerce' ) . '">';
- if ( $the_product->is_featured() ) {
- echo '<span class="wc-featured tips" data-tip="' . __( 'Yes', 'woocommerce' ) . '">' . __( 'Yes', 'woocommerce' ) . '</span>';
- } else {
- echo '<span class="wc-featured not-featured tips" data-tip="' . __( 'No', 'woocommerce' ) . '">' . __( 'No', 'woocommerce' ) . '</span>';
- }
- echo '</a>';
- break;
- case 'is_in_stock' :
- if ( $the_product->is_in_stock() ) {
- echo '<mark class="instock">' . __( 'In stock', 'woocommerce' ) . '</mark>';
- } else {
- echo '<mark class="outofstock">' . __( 'Out of stock', 'woocommerce' ) . '</mark>';
- }
- if ( $the_product->managing_stock() ) {
- echo ' × ' . $the_product->get_total_stock();
- }
- break;
- default :
- break;
- }
- }
- /**
- * Output custom columns for coupons
- * @param string $column
- */
- public function render_shop_coupon_columns( $column ) {
- global $post, $woocommerce;
- switch ( $column ) {
- case "coupon_code" :
- $edit_link = get_edit_post_link( $post->ID );
- $title = _draft_or_post_title();
- $post_type_object = get_post_type_object( $post->post_type );
- $can_edit_post = current_user_can( $post_type_object->cap->edit_post, $post->ID );
- echo '<div class="code tips" data-tip="' . __( 'Edit coupon', 'woocommerce' ) . '"><a href="' . esc_attr( $edit_link ) . '"><span>' . esc_html( $title ). '</span></a></div>';
- _post_states( $post );
- // Get actions
- $actions = array();
- if ( current_user_can( $post_type_object->cap->delete_post, $post->ID ) ) {
- if ( 'trash' == $post->post_status )
- $actions['untrash'] = "<a title='" . esc_attr( __( 'Restore this item from the Trash', 'woocommerce' ) ) . "' href='" . wp_nonce_url( admin_url( sprintf( $post_type_object->_edit_link . '&action=untrash', $post->ID ) ), 'untrash-post_' . $post->ID ) . "'>" . __( 'Restore', 'woocommerce' ) . "</a>";
- elseif ( EMPTY_TRASH_DAYS )
- $actions['trash'] = "<a class='submitdelete' title='" . esc_attr( __( 'Move this item to the Trash', 'woocommerce' ) ) . "' href='" . get_delete_post_link( $post->ID ) . "'>" . __( 'Trash', 'woocommerce' ) . "</a>";
- if ( 'trash' == $post->post_status || !EMPTY_TRASH_DAYS )
- $actions['delete'] = "<a class='submitdelete' title='" . esc_attr( __( 'Delete this item permanently', 'woocommerce' ) ) . "' href='" . get_delete_post_link( $post->ID, '', true ) . "'>" . __( 'Delete Permanently', 'woocommerce' ) . "</a>";
- }
- $actions = apply_filters( 'post_row_actions', $actions, $post );
- echo '<div class="row-actions">';
- $i = 0;
- $action_count = sizeof($actions);
- foreach ( $actions as $action => $link ) {
- ++$i;
- ( $i == $action_count ) ? $sep = '' : $sep = ' | ';
- echo "<span class='$action'>$link$sep</span>";
- }
- echo '</div>';
- break;
- case "type" :
- echo esc_html( wc_get_coupon_type( get_post_meta( $post->ID, 'discount_type', true ) ) );
- break;
- case "amount" :
- echo esc_html( get_post_meta( $post->ID, 'coupon_amount', true ) );
- break;
- case "products" :
- $product_ids = get_post_meta( $post->ID, 'product_ids', true );
- $product_ids = $product_ids ? array_map( 'absint', explode( ',', $product_ids ) ) : array();
- if ( sizeof( $product_ids ) > 0 )
- echo esc_html( implode( ', ', $product_ids ) );
- else
- echo '–';
- break;
- case "usage_limit" :
- $usage_limit = get_post_meta( $post->ID, 'usage_limit', true );
- if ( $usage_limit )
- echo esc_html( $usage_limit );
- else
- echo '–';
- break;
- case "usage" :
- $usage_count = absint( get_post_meta( $post->ID, 'usage_count', true ) );
- $usage_limit = esc_html( get_post_meta($post->ID, 'usage_limit', true) );
- if ( $usage_limit )
- printf( __( '%s / %s', 'woocommerce' ), $usage_count, $usage_limit );
- else
- printf( __( '%s / ∞', 'woocommerce' ), $usage_count );
- break;
- case "expiry_date" :
- $expiry_date = get_post_meta($post->ID, 'expiry_date', true);
- if ( $expiry_date )
- echo esc_html( date_i18n( 'F j, Y', strtotime( $expiry_date ) ) );
- else
- echo '–';
- break;
- case "description" :
- echo wp_kses_post( $post->post_excerpt );
- break;
- }
- }
- /**
- * Output custom columns for coupons
- * @param string $column
- */
- public function render_shop_order_columns( $column ) {
- global $post, $woocommerce, $the_order;
- if ( empty( $the_order ) || $the_order->id != $post->ID ) {
- $the_order = wc_get_order( $post->ID );
- }
- switch ( $column ) {
- case 'order_status' :
- printf( '<mark class="%s tips" data-tip="%s">%s</mark>', sanitize_title( $the_order->get_status() ), wc_get_order_status_name( $the_order->get_status() ), wc_get_order_status_name( $the_order->get_status() ) );
- break;
- case 'order_date' :
- if ( '0000-00-00 00:00:00' == $post->post_date ) {
- $t_time = $h_time = __( 'Unpublished', 'woocommerce' );
- } else {
- $t_time = get_the_time( __( 'Y/m/d g:i:s A', 'woocommerce' ), $post );
- $gmt_time = strtotime( $post->post_date_gmt . ' UTC' );
- $time_diff = current_time( 'timestamp', 1 ) - $gmt_time;
- $h_time = get_the_time( __( 'Y/m/d', 'woocommerce' ), $post );
- }
- echo '<abbr title="' . esc_attr( $t_time ) . '">' . esc_html( apply_filters( 'post_date_column_time', $h_time, $post ) ) . '</abbr>';
- break;
- case 'customer_message' :
- if ( $the_order->customer_message )
- echo '<span class="note-on tips" data-tip="' . esc_attr( $the_order->customer_message ) . '">' . __( 'Yes', 'woocommerce' ) . '</span>';
- else
- echo '<span class="na">–</span>';
- break;
- case 'order_items' :
- echo '<a href="#" class="show_order_items">' . apply_filters( 'woocommerce_admin_order_item_count', sprintf( _n( '%d item', '%d items', $the_order->get_item_count(), 'woocommerce' ), $the_order->get_item_count() ), $the_order ) . '</a>';
- if ( sizeof( $the_order->get_items() ) > 0 ) {
- echo '<table class="order_items" cellspacing="0">';
- foreach ( $the_order->get_items() as $item ) {
- $_product = apply_filters( 'woocommerce_order_item_product', $the_order->get_product_from_item( $item ), $item );
- $item_meta = new WC_Order_Item_Meta( $item['item_meta'] );
- $item_meta_html = $item_meta->display( true, true );
- ?>
- <tr class="<?php echo apply_filters( 'woocommerce_admin_order_item_class', '', $item ); ?>">
- <td class="qty"><?php echo absint( $item['qty'] ); ?></td>
- <td class="name">
- <?php if ( wc_product_sku_enabled() && $_product && $_product->get_sku() ) echo $_product->get_sku() . ' - '; ?><?php echo apply_filters( 'woocommerce_order_item_name', $item['name'], $item ); ?>
- <?php if ( $item_meta_html ) : ?>
- <a class="tips" href="#" data-tip="<?php echo esc_attr( $item_meta_html ); ?>">[?]</a>
- <?php endif; ?>
- </td>
- </tr>
- <?php
- }
- echo '</table>';
- } else echo '–';
- break;
- case 'shipping_address' :
- if ( $the_order->get_formatted_shipping_address() )
- echo '<a target="_blank" href="' . esc_url( 'http://maps.google.com/maps?&q=' . urlencode( $the_order->get_shipping_address() ) . '&z=16' ) . '">'. esc_html( preg_replace( '#<br\s*/?>#i', ', ', $the_order->get_formatted_shipping_address() ) ) .'</a>';
- else
- echo '–';
- if ( $the_order->get_shipping_method() )
- echo '<small class="meta">' . __( 'Via', 'woocommerce' ) . ' ' . esc_html( $the_order->get_shipping_method() ) . '</small>';
- break;
- case 'order_notes' :
- if ( $post->comment_count ) {
- // check the status of the post
- ( $post->post_status !== 'trash' ) ? $status = '' : $status = 'post-trashed';
- $latest_notes = get_comments( array(
- 'post_id' => $post->ID,
- 'number' => 1,
- 'status' => $status
- ) );
- $latest_note = current( $latest_notes );
- if ( $post->comment_count == 1 ) {
- echo '<span class="note-on tips" data-tip="' . esc_attr( $latest_note->comment_content ) . '">' . __( 'Yes', 'woocommerce' ) . '</span>';
- } else {
- $note_tip = isset( $latest_note->comment_content ) ? esc_attr( $latest_note->comment_content . '<small style="display:block">' . sprintf( _n( 'plus %d other note', 'plus %d other notes', ( $post->comment_count - 1 ), 'woocommerce' ), ( $post->comment_count - 1 ) ) . '</small>' ) : sprintf( _n( '%d note', '%d notes', $post->comment_count, 'woocommerce' ), $post->comment_count );
- echo '<span class="note-on tips" data-tip="' . $note_tip . '">' . __( 'Yes', 'woocommerce' ) . '</span>';
- }
- } else {
- echo '<span class="na">–</span>';
- }
- break;
- case 'order_total' :
- echo esc_html( strip_tags( $the_order->get_formatted_order_total() ) );
- if ( $the_order->payment_method_title ) {
- echo '<small class="meta">' . __( 'Via', 'woocommerce' ) . ' ' . esc_html( $the_order->payment_method_title ) . '</small>';
- }
- break;
- case 'order_title' :
- $customer_tip = '';
- if ( $address = $the_order->get_formatted_billing_address() ) {
- $customer_tip .= __( 'Billing:', 'woocommerce' ) . ' ' . $address . '<br/><br/>';
- }
- if ( $the_order->billing_phone ) {
- $customer_tip .= __( 'Tel:', 'woocommerce' ) . ' ' . $the_order->billing_phone;
- }
- echo '<div class="tips" data-tip="' . esc_attr( $customer_tip ) . '">';
- if ( $the_order->user_id ) {
- $user_info = get_userdata( $the_order->user_id );
- }
- if ( ! empty( $user_info ) ) {
- $username = '<a href="user-edit.php?user_id=' . absint( $user_info->ID ) . '">';
- if ( $user_info->first_name || $user_info->last_name ) {
- $username .= esc_html( ucfirst( $user_info->first_name ) . ' ' . ucfirst( $user_info->last_name ) );
- } else {
- $username .= esc_html( ucfirst( $user_info->display_name ) );
- }
- $username .= '</a>';
- } else {
- if ( $the_order->billing_first_name || $the_order->billing_last_name ) {
- $username = trim( $the_order->billing_first_name . ' ' . $the_order->billing_last_name );
- } else {
- $username = __( 'Guest', 'woocommerce' );
- }
- }
- printf( __( '%s by %s', 'woocommerce' ), '<a href="' . admin_url( 'post.php?post=' . absint( $post->ID ) . '&action=edit' ) . '"><strong>' . esc_attr( $the_order->get_order_number() ) . '</strong></a>', $username );
- if ( $the_order->billing_email ) {
- echo '<small class="meta email"><a href="' . esc_url( 'mailto:' . $the_order->billing_email ) . '">' . esc_html( $the_order->billing_email ) . '</a></small>';
- }
- echo '</div>';
- break;
- case 'order_actions' :
- ?><p>
- <?php
- do_action( 'woocommerce_admin_order_actions_start', $the_order );
- $actions = array();
- if ( $the_order->has_status( array( 'pending', 'on-hold' ) ) ) {
- $actions['processing'] = array(
- 'url' => wp_nonce_url( admin_url( 'admin-ajax.php?action=woocommerce_mark_order_processing&order_id=' . $post->ID ), 'woocommerce-mark-order-processing' ),
- 'name' => __( 'Processing', 'woocommerce' ),
- 'action' => "processing"
- );
- }
- if ( $the_order->has_status( array( 'pending', 'on-hold', 'processing' ) ) ) {
- $actions['complete'] = array(
- 'url' => wp_nonce_url( admin_url( 'admin-ajax.php?action=woocommerce_mark_order_complete&order_id=' . $post->ID ), 'woocommerce-mark-order-complete' ),
- 'name' => __( 'Complete', 'woocommerce' ),
- 'action' => "complete"
- );
- }
- $actions['view'] = array(
- 'url' => admin_url( 'post.php?post=' . $post->ID . '&action=edit' ),
- 'name' => __( 'View', 'woocommerce' ),
- 'action' => "view"
- );
- $actions = apply_filters( 'woocommerce_admin_order_actions', $actions, $the_order );
- foreach ( $actions as $action ) {
- printf( '<a class="button tips %s" href="%s" data-tip="%s">%s</a>', esc_attr( $action['action'] ), esc_url( $action['url'] ), esc_attr( $action['name'] ), esc_attr( $action['name'] ) );
- }
- do_action( 'woocommerce_admin_order_actions_end', $the_order );
- ?>
- </p><?php
- break;
- }
- }
- /**
- * Make columns sortable - https://gist.github.com/906872
- *
- * @param array $columns
- * @return array
- */
- public function product_sortable_columns( $columns ) {
- $custom = array(
- 'price' => 'price',
- 'featured' => 'featured',
- 'sku' => 'sku',
- 'name' => 'title'
- );
- return wp_parse_args( $custom, $columns );
- }
- /**
- * Make columns sortable - https://gist.github.com/906872
- *
- * @param array $columns
- * @return array
- */
- public function shop_coupon_sortable_columns( $columns ) {
- return $columns;
- }
- /**
- * Make columns sortable - https://gist.github.com/906872
- *
- * @param array $columns
- * @return array
- */
- public function shop_order_sortable_columns( $columns ) {
- $custom = array(
- 'order_title' => 'ID',
- 'order_total' => 'order_total',
- 'order_date' => 'date'
- );
- unset( $columns['comments'] );
- return wp_parse_args( $custom, $columns );
- }
- /**
- * Remove edit from the bulk actions.
- *
- * @param array $actions
- * @return array
- */
- public function shop_order_bulk_actions( $actions ) {
- if ( isset( $actions['edit'] ) ) {
- unset( $actions['edit'] );
- }
- return $actions;
- }
- /**
- * Product sorting link
- *
- * Based on Simple Page Ordering by 10up (http://wordpress.org/extend/plugins/simple-page-ordering/)
- *
- * @param array $views
- * @return array
- */
- public function product_sorting_link( $views ) {
- global $post_type, $wp_query;
- if ( ! current_user_can('edit_others_pages') ) {
- return $views;
- }
- $class = ( isset( $wp_query->query['orderby'] ) && $wp_query->query['orderby'] == 'menu_order title' ) ? 'current' : '';
- $query_string = remove_query_arg(array( 'orderby', 'order' ));
- $query_string = add_query_arg( 'orderby', urlencode('menu_order title'), $query_string );
- $query_string = add_query_arg( 'order', urlencode('ASC'), $query_string );
- $views['byorder'] = '<a href="'. $query_string . '" class="' . esc_attr( $class ) . '">' . __( 'Sort Products', 'woocommerce' ) . '</a>';
- return $views;
- }
- /**
- * Custom bulk edit - form
- *
- * @access public
- * @param mixed $column_name
- * @param mixed $post_type
- */
- public function bulk_edit( $column_name, $post_type ) {
- if ( 'price' != $column_name || 'product' != $post_type ) {
- return;
- }
- include( WC()->plugin_path() . '/includes/admin/views/html-bulk-edit-product.php' );
- }
- /**
- * Custom quick edit - form
- *
- * @access public
- * @param mixed $column_name
- * @param mixed $post_type
- */
- public function quick_edit( $column_name, $post_type ) {
- if ( 'price' != $column_name || 'product' != $post_type ) {
- return;
- }
- include( WC()->plugin_path() . '/includes/admin/views/html-quick-edit-product.php' );
- }
- /**
- * Quick and bulk edit saving
- *
- * @access public
- * @param int $post_id
- * @param WP_Post $post
- * @return int
- */
- public function bulk_and_quick_edit_save_post( $post_id, $post ) {
- // If this is an autosave, our form has not been submitted, so we don't want to do anything.
- if ( defined( 'DOING_AUTOSAVE' ) && DOING_AUTOSAVE ) {
- return $post_id;
- }
- // Don't save revisions and autosaves
- if ( wp_is_post_revision( $post_id ) || wp_is_post_autosave( $post_id ) ) {
- return $post_id;
- }
- // Check post type is product
- if ( 'product' != $post->post_type ) {
- return $post_id;
- }
- // Check user permission
- if ( ! current_user_can( 'edit_post', $post_id ) ) {
- return $post_id;
- }
- // Check nonces
- if ( ! isset( $_REQUEST['woocommerce_quick_edit_nonce'] ) && ! isset( $_REQUEST['woocommerce_bulk_edit_nonce'] ) ) {
- return $post_id;
- }
- if ( isset( $_REQUEST['woocommerce_quick_edit_nonce'] ) && ! wp_verify_nonce( $_REQUEST['woocommerce_quick_edit_nonce'], 'woocommerce_quick_edit_nonce' ) ) {
- return $post_id;
- }
- if ( isset( $_REQUEST['woocommerce_bulk_edit_nonce'] ) && ! wp_verify_nonce( $_REQUEST['woocommerce_bulk_edit_nonce'], 'woocommerce_bulk_edit_nonce' ) ) {
- return $post_id;
- }
- // Get the product and save
- $product = wc_get_product( $post );
- if ( ! empty( $_REQUEST['woocommerce_quick_edit'] ) ) {
- $this->quick_edit_save( $post_id, $product );
- } else {
- $this->bulk_edit_save( $post_id, $product );
- }
- // Clear transient
- wc_delete_product_transients( $post_id );
- return $post_id;
- }
- /**
- * Quick edit
- * @param integer $post_id
- */
- private function quick_edit_save( $post_id, $product ) {
- global $wpdb;
- $old_regular_price = $product->regular_price;
- $old_sale_price = $product->sale_price;
- // Save fields
- if ( isset( $_REQUEST['_sku'] ) ) {
- $sku = get_post_meta( $post_id, '_sku', true );
- $new_sku = wc_clean( stripslashes( $_REQUEST['_sku'] ) );
- if ( $new_sku !== $sku ) {
- if ( ! empty( $new_sku ) ) {
- $unique_sku = wc_product_has_unique_sku( $post_id, $new_sku );
- if ( $unique_sku ) {
- update_post_meta( $post_id, '_sku', $new_sku );
- }
- } else {
- update_post_meta( $post_id, '_sku', '' );
- }
- }
- }
- if ( isset( $_REQUEST['_weight'] ) ) {
- update_post_meta( $post_id, '_weight', wc_clean( $_REQUEST['_weight'] ) );
- }
- if ( isset( $_REQUEST['_length'] ) ) {
- update_post_meta( $post_id, '_length', wc_clean( $_REQUEST['_length'] ) );
- }
- if ( isset( $_REQUEST['_width'] ) ) {
- update_post_meta( $post_id, '_width', wc_clean( $_REQUEST['_width'] ) );
- }
- if ( isset( $_REQUEST['_height'] ) ) {
- update_post_meta( $post_id, '_height', wc_clean( $_REQUEST['_height'] ) );
- }
- if ( isset( $_REQUEST['_visibility'] ) ) {
- if ( update_post_meta( $post_id, '_visibility', wc_clean( $_REQUEST['_visibility'] ) ) ) {
- do_action( 'woocommerce_product_set_visibility', $post_id, wc_clean( $_REQUEST['_visibility'] ) );
- }
- }
- if ( isset( $_REQUEST['_featured'] ) ) {
- if ( update_post_meta( $post_id, '_featured', 'yes' ) ) {
- delete_transient( 'wc_featured_products' );
- }
- } else {
- if ( update_post_meta( $post_id, '_featured', 'no' ) ) {
- delete_transient( 'wc_featured_products' );
- }
- }
- if ( isset( $_REQUEST['_tax_status'] ) ) {
- update_post_meta( $post_id, '_tax_status', wc_clean( $_REQUEST['_tax_status'] ) );
- }
- if ( isset( $_REQUEST['_tax_class'] ) ) {
- update_post_meta( $post_id, '_tax_class', wc_clean( $_REQUEST['_tax_class'] ) );
- }
- if ( $product->is_type('simple') || $product->is_type('external') ) {
- if ( isset( $_REQUEST['_regular_price'] ) ) {
- $new_regular_price = $_REQUEST['_regular_price'] === '' ? '' : wc_format_decimal( $_REQUEST['_regular_price'] );
- update_post_meta( $post_id, '_regular_price', $new_regular_price );
- } else {
- $new_regular_price = null;
- }
- if ( isset( $_REQUEST['_sale_price'] ) ) {
- $new_sale_price = $_REQUEST['_sale_price'] === '' ? '' : wc_format_decimal( $_REQUEST['_sale_price'] );
- update_post_meta( $post_id, '_sale_price', $new_sale_price );
- } else {
- $new_sale_price = null;
- }
- // Handle price - remove dates and set to lowest
- $price_changed = false;
- if ( ! is_null( $new_regular_price ) && $new_regular_price != $old_regular_price ) {
- $price_changed = true;
- } elseif ( ! is_null( $new_sale_price ) && $new_sale_price != $old_sale_price ) {
- $price_changed = true;
- }
- if ( $price_changed ) {
- update_post_meta( $post_id, '_sale_price_dates_from', '' );
- update_post_meta( $post_id, '_sale_price_dates_to', '' );
- if ( ! is_null( $new_sale_price ) && $new_sale_price !== '' ) {
- update_post_meta( $post_id, '_price', $new_sale_price );
- } else {
- update_post_meta( $post_id, '_price', $new_regular_price );
- }
- }
- }
- // Handle stock status
- if ( isset( $_REQUEST['_stock_status'] ) ) {
- wc_update_product_stock_status( $post_id, wc_clean( $_REQUEST['_stock_status'] ) );
- }
- // Handle stock
- if ( ! $product->is_type('grouped') ) {
- if ( isset( $_REQUEST['_manage_stock'] ) ) {
- update_post_meta( $post_id, '_manage_stock', 'yes' );
- wc_update_product_stock( $post_id, wc_stock_amount( $_REQUEST['_stock'] ) );
- } else {
- update_post_meta( $post_id, '_manage_stock', 'no' );
- wc_update_product_stock( $post_id, 0 );
- }
- if ( ! empty( $_REQUEST['_backorders'] ) ) {
- update_post_meta( $post_id, '_backorders', wc_clean( $_REQUEST['_backorders'] ) );
- }
- }
- do_action( 'woocommerce_product_quick_edit_save', $product );
- }
- /**
- * Bulk edit
- * @param integer $post_id
- */
- public function bulk_edit_save( $post_id, $product ) {
- $old_regular_price = $product->regular_price;
- $old_sale_price = $product->sale_price;
- // Save fields
- if ( ! empty( $_REQUEST['change_weight'] ) && isset( $_REQUEST['_weight'] ) ) {
- update_post_meta( $post_id, '_weight', wc_clean( stripslashes( $_REQUEST['_weight'] ) ) );
- }
- if ( ! empty( $_REQUEST['change_dimensions'] ) ) {
- if ( isset( $_REQUEST['_length'] ) ) {
- update_post_meta( $post_id, '_length', wc_clean( stripslashes( $_REQUEST['_length'] ) ) );
- }
- if ( isset( $_REQUEST['_width'] ) ) {
- update_post_meta( $post_id, '_width', wc_clean( stripslashes( $_REQUEST['_width'] ) ) );
- }
- if ( isset( $_REQUEST['_height'] ) ) {
- update_post_meta( $post_id, '_height', wc_clean( stripslashes( $_REQUEST['_height'] ) ) );
- }
- }
- if ( ! empty( $_REQUEST['_tax_status'] ) ) {
- update_post_meta( $post_id, '_tax_status', wc_clean( $_REQUEST['_tax_status'] ) );
- }
- if ( ! empty( $_REQUEST['_tax_class'] ) ) {
- $tax_class = wc_clean( $_REQUEST['_tax_class'] );
- if ( 'standard' == $tax_class ) {
- $tax_class = '';
- }
- update_post_meta( $post_id, '_tax_class', $tax_class );
- }
- if ( ! empty( $_REQUEST['_stock_status'] ) ) {
- wc_update_product_stock_status( $post_id, wc_clean( $_REQUEST['_stock_status'] ) );
- }
- if ( ! empty( $_REQUEST['_visibility'] ) ) {
- if ( update_post_meta( $post_id, '_visibility', wc_clean( $_REQUEST['_visibility'] ) ) ) {
- do_action( 'woocommerce_product_set_visibility', $post_id, wc_clean( $_REQUEST['_visibility'] ) );
- }
- }
- if ( ! empty( $_REQUEST['_featured'] ) ) {
- if ( update_post_meta( $post_id, '_featured', stripslashes( $_REQUEST['_featured'] ) ) ) {
- delete_transient( 'wc_featured_products' );
- }
- }
- // Sold Individually
- if ( ! empty( $_REQUEST['_sold_individually'] ) ) {
- if ( $_REQUEST['_sold_individually'] == 'yes' ) {
- update_post_meta( $post_id, '_sold_individually', 'yes' );
- }
- else {
- update_post_meta( $post_id, '_sold_individually', '' );
- }
- }
- // Handle price - remove dates and set to lowest
- if ( $product->is_type( 'simple' ) || $product->is_type( 'external' ) ) {
- $price_changed = false;
- if ( ! empty( $_REQUEST['change_regular_price'] ) ) {
- $change_regular_price = absint( $_REQUEST['change_regular_price'] );
- $regular_price = esc_attr( stripslashes( $_REQUEST['_regular_price'] ) );
- switch ( $change_regular_price ) {
- case 1 :
- $new_price = $regular_price;
- break;
- case 2 :
- if ( strstr( $regular_price, '%' ) ) {
- $percent = str_replace( '%', '', $regular_price ) / 100;
- $new_price = $old_regular_price + ( round( $old_regular_price * $percent, absint( get_option( 'woocommerce_price_num_decimals' ) ) ) );
- } else {
- $new_price = $old_regular_price + $regular_price;
- }
- break;
- case 3 :
- if ( strstr( $regular_price, '%' ) ) {
- $percent = str_replace( '%', '', $regular_price ) / 100;
- $new_price = max( 0, $old_regular_price - ( round ( $old_regular_price * $percent, absint( get_option( 'woocommerce_price_num_decimals' ) ) ) ) );
- } else {
- $new_price = max( 0, $old_regular_price - $regular_price );
- }
- break;
- default :
- break;
- }
- if ( isset( $new_price ) && $new_price != $old_regular_price ) {
- $price_changed = true;
- $new_price = round( $new_price, absint( get_option( 'woocommerce_price_num_decimals' ) ) );
- update_post_meta( $post_id, '_regular_price', $new_price );
- $product->regular_price = $new_price;
- }
- }
- if ( ! empty( $_REQUEST['change_sale_price'] ) ) {
- $change_sale_price = absint( $_REQUEST['change_sale_price'] );
- $sale_price = esc_attr( stripslashes( $_REQUEST['_sale_price'] ) );
- switch ( $change_sale_price ) {
- case 1 :
- $new_price = $sale_price;
- break;
- case 2 :
- if ( strstr( $sale_price, '%' ) ) {
- $percent = str_replace( '%', '', $sale_price ) / 100;
- $new_price = $old_sale_price + ( $old_sale_price * $percent );
- } else {
- $new_price = $old_sale_price + $sale_price;
- }
- break;
- case 3 :
- if ( strstr( $sale_price, '%' ) ) {
- $percent = str_replace( '%', '', $sale_price ) / 100;
- $new_price = max( 0, $old_sale_price - ( $old_sale_price * $percent ) );
- } else {
- $new_price = max( 0, $old_sale_price - $sale_price );
- }
- break;
- case 4 :
- if ( strstr( $sale_price, '%' ) ) {
- $percent = str_replace( '%', '', $sale_price ) / 100;
- $new_price = max( 0, $product->regular_price - ( $product->regular_price * $percent ) );
- } else {
- $new_price = max( 0, $product->regular_price - $sale_price );
- }
- break;
- default :
- break;
- }
- if ( isset( $new_price ) && $new_price != $old_sale_price ) {
- $price_changed = true;
- $new_price = round( $new_price, absint( get_option( 'woocommerce_price_num_decimals' ) ) );
- update_post_meta( $post_id, '_sale_price', $new_price );
- $product->sale_price = $new_price;
- }
- }
- if ( $price_changed ) {
- update_post_meta( $post_id, '_sale_price_dates_from', '' );
- update_post_meta( $post_id, '_sale_price_dates_to', '' );
- if ( $product->regular_price < $product->sale_price ) {
- $product->sale_price = '';
- update_post_meta( $post_id, '_sale_price', '' );
- }
- if ( $product->sale_price ) {
- update_post_meta( $post_id, '_price', $product->sale_price );
- } else {
- update_post_meta( $post_id, '_price', $product->regular_price );
- }
- }
- }
- // Handle stock
- if ( ! $product->is_type( 'grouped' ) ) {
- if ( ! empty( $_REQUEST['change_stock'] ) ) {
- update_post_meta( $post_id, '_manage_stock', 'yes' );
- wc_update_product_stock( $post_id, wc_stock_amount( $_REQUEST['_stock'] ) );
- }
- if ( ! empty( $_REQUEST['_manage_stock'] ) ) {
- if ( $_REQUEST['_manage_stock'] == 'yes' ) {
- update_post_meta( $post_id, '_manage_stock', 'yes' );
- } else {
- update_post_meta( $post_id, '_manage_stock', 'no' );
- wc_update_product_stock( $post_id, 0 );
- }
- }
- if ( ! empty( $_REQUEST['_backorders'] ) ) {
- update_post_meta( $post_id, '_backorders', wc_clean( $_REQUEST['_backorders'] ) );
- }
- }
- do_action( 'woocommerce_product_bulk_edit_save', $product );
- }
- /**
- * Add extra bulk action options to mark orders as complete or processing
- *
- * Using Javascript until WordPress core fixes: http://core.trac.wordpress.org/ticket/16031
- *
- * @access public
- * @return void
- */
- public function bulk_admin_footer() {
- global $post_type;
- if ( 'shop_order' == $post_type ) {
- ?>
- <script type="text/javascript">
- jQuery(function() {
- jQuery('<option>').val('mark_processing').text('<?php _e( 'Mark processing', 'woocommerce' )?>').appendTo("select[name='action']");
- jQuery('<option>').val('mark_processing').text('<?php _e( 'Mark processing', 'woocommerce' )?>').appendTo("select[name='action2']");
- jQuery('<option>').val('mark_on-hold').text('<?php _e( 'Mark on-hold', 'woocommerce' )?>').appendTo("select[name='action']");
- jQuery('<option>').val('mark_on-hold').text('<?php _e( 'Mark on-hold', 'woocommerce' )?>').appendTo("select[name='action2']");
- jQuery('<option>').val('mark_completed').text('<?php _e( 'Mark complete', 'woocommerce' )?>').appendTo("select[name='action']");
- jQuery('<option>').val('mark_completed').text('<?php _e( 'Mark complete', 'woocommerce' )?>').appendTo("select[name='action2']");
- });
- </script>
- <?php
- }
- }
- /**
- * Process the new bulk actions for changing order status
- *
- * @access public
- * @return void
- */
- public function bulk_action() {
- $wp_list_table = _get_list_table( 'WP_Posts_List_Table' );
- $action = $wp_list_table->current_action();
- switch ( $action ) {
- case 'mark_completed':
- $new_status = 'completed';
- $report_action = 'marked_complete';
- break;
- case 'mark_processing':
- $new_status = 'processing';
- $report_action = 'marked_processing';
- break;
- case 'mark_on-hold' :
- $new_status = 'on-hold';
- $report_action = 'marked_on-hold';
- break;
- break;
- default:
- return;
- }
- $changed = 0;
- $post_ids = array_map( 'absint', (array) $_REQUEST['post'] );
- foreach ( $post_ids as $post_id ) {
- $order = wc_get_order( $post_id );
- $order->update_status( $new_status, __( 'Order status changed by bulk edit:', 'woocommerce' ) );
- $changed++;
- }
- $sendback = add_query_arg( array( 'post_type' => 'shop_order', $report_action => true, 'changed' => $changed, 'ids' => join( ',', $post_ids ) ), '' );
- wp_redirect( $sendback );
- exit();
- }
- /**
- * Show confirmation message that order status changed for number of orders
- *
- * @access public
- * @return void
- */
- public function bulk_admin_notices() {
- global $post_type, $pagenow;
- if ( isset( $_REQUEST['marked_complete'] ) || isset( $_REQUEST['marked_processing'] ) || isset( $_REQUEST['marked_on-hold'] ) ) {
- $number = isset( $_REQUEST['changed'] ) ? absint( $_REQUEST['changed'] ) : 0;
- if ( 'edit.php' == $pagenow && 'shop_order' == $post_type ) {
- $message = sprintf( _n( 'Order status changed.', '%s order statuses changed.', $number, 'woocommerce' ), number_format_i18n( $number ) );
- echo '<div class="updated"><p>' . $message . '</p></div>';
- }
- }
- }
- /**
- * Search custom fields as well as content.
- *
- * @access public
- * @param WP_Query $wp
- * @return void
- */
- public function shop_order_search_custom_fields( $wp ) {
- global $pagenow, $wpdb;
- if ( 'edit.php' != $pagenow || empty( $wp->query_vars['s'] ) || $wp->query_vars['post_type'] != 'shop_order' ) {
- return;
- }
- $search_fields = array_map( 'wc_clean', apply_filters( 'woocommerce_shop_order_search_fields', array(
- '_order_key',
- '_billing_company',
- '_billing_address_1',
- '_billing_address_2',
- '_billing_city',
- '_billing_postcode',
- '_billing_country',
- '_billing_state',
- '_billing_email',
- '_billing_phone',
- '_shipping_address_1',
- '_shipping_address_2',
- '_shipping_city',
- '_shipping_postcode',
- '_shipping_country',
- '_shipping_state'
- ) ) );
- $search_order_id = str_replace( 'Order #', '', $_GET['s'] );
- if ( ! is_numeric( $search_order_id ) ) {
- $search_order_id = 0;
- }
- // Search orders
- $post_ids = array_unique( array_merge(
- $wpdb->get_col(
- $wpdb->prepare( "
- SELECT p1.post_id
- FROM {$wpdb->postmeta} p1
- INNER JOIN {$wpdb->postmeta} p2 ON p1.post_id = p2.post_id
- WHERE
- ( p1.meta_key = '_billing_first_name' AND p2.meta_key = '_billing_last_name' AND CONCAT(p1.meta_value, ' ', p2.meta_value) LIKE '%%%s%%' )
- OR
- ( p1.meta_key = '_shipping_first_name' AND p2.meta_key = '_shipping_last_name' AND CONCAT(p1.meta_value, ' ', p2.meta_value) LIKE '%%%s%%' )
- OR
- ( p1.meta_key IN ('" . implode( "','", $search_fields ) . "') AND p1.meta_value LIKE '%%%s%%' )
- ",
- esc_attr( $_GET['s'] ), esc_attr( $_GET['s'] ), esc_attr( $_GET['s'] )
- )
- ),
- $wpdb->get_col(
- $wpdb->prepare( "
- SELECT order_id
- FROM {$wpdb->prefix}woocommerce_order_items as order_items
- WHERE order_item_name LIKE '%%%s%%'
- ",
- esc_attr( $_GET['s'] )
- )
- ),
- array( $search_order_id )
- ) );
- // Remove s - we don't want to search order name
- unset( $wp->query_vars['s'] );
- // so we know we're doing this
- $wp->query_vars['shop_order_search'] = true;
- // Search by found posts
- $wp->query_vars['post__in'] = $post_ids;
- }
- /**
- * Change the label when searching orders.
- *
- * @access public
- * @param mixed $query
- * @return string
- */
- public function shop_order_search_label( $query ) {
- global $pagenow, $typenow;
- if ( 'edit.php' != $pagenow ) {
- return $query;
- }
- if ( $typenow != 'shop_order' ) {
- return $query;
- }
- if ( ! get_query_var( 'shop_order_search' ) ) {
- return $query;
- }
- return wp_unslash( $_GET['s'] );
- }
- /**
- * Query vars for custom searches.
- *
- * @access public
- * @param mixed $public_query_vars
- * @return array
- */
- public function add_custom_query_var( $public_query_vars ) {
- $public_query_vars[] = 'sku';
- $public_query_vars[] = 'shop_order_search';
- return $public_query_vars;
- }
- /**
- * Filters for post types
- */
- public function restrict_manage_posts() {
- global $typenow, $wp_query;
- switch ( $typenow ) {
- case 'product' :
- $this->product_filters();
- break;
- case 'shop_coupon' :
- $this->shop_coupon_filters();
- break;
- case 'shop_order' :
- $this->shop_order_filters();
- break;
- default :
- break;
- }
- }
- /**
- * Show a category filter box
- */
- public function product_filters() {
- global $wp_query;
- // Category Filtering
- wc_product_dropdown_categories();
- // Type filtering
- $terms = get_terms( 'product_type' );
- $output = '<select name="product_type" id="dropdown_product_type">';
- $output .= '<option value="">' . __( 'Show all product types', 'woocommerce' ) . '</option>';
- foreach ( $terms as $term ) {
- $output .= '<option value="' . sanitize_title( $term->name ) . '" ';
- if ( isset( $wp_query->query['product_type'] ) ) {
- $output .= selected( $term->slug, $wp_query->query['product_type'], false );
- }
- $output .= '>';
- switch ( $term->name ) {
- case 'grouped' :
- $output .= __( 'Grouped product', 'woocommerce' );
- break;
- case 'external' :
- $output .= __( 'External/Affiliate product', 'woocommerce' );
- break;
- case 'variable' :
- $output .= __( 'Variable product', 'woocommerce' );
- break;
- case 'simple' :
- $output .= __( 'Simple product', 'woocommerce' );
- break;
- default :
- // Assuming that we have other types in future
- $output .= ucfirst( $term->name );
- break;
- }
- $output .= " ($term->count)</option>";
- if ( 'simple' == $term->name ) {
- $output .= '<option value="downloadable" ';
- if ( isset( $wp_query->query['product_type'] ) ) {
- $output .= selected( 'downloadable', $wp_query->query['product_type'], false );
- }
- $output .= '> → ' . __( 'Downloadable', 'woocommerce' ) . '</option>';
- $output .= '<option value="virtual" ';
- if ( isset( $wp_query->query['product_type'] ) ) {
- $output .= selected( 'virtual'…
Large files files are truncated, but you can click here to view the full file