2013-07-24 16:01:36 +00:00
< ? php
/**
2015-11-03 13:53:50 +00:00
* Post Types Admin
2013-07-24 16:01:36 +00:00
*
2016-11-16 20:48:42 +00:00
* @ author WooCommerce
2015-07-20 17:15:51 +00:00
* @ category Admin
* @ package WooCommerce / Admin
2017-03-15 16:36:53 +00:00
* @ version 3.0 . 0
2013-07-24 16:01:36 +00:00
*/
2014-09-20 19:52:30 +00:00
if ( ! defined ( 'ABSPATH' ) ) {
2016-11-16 20:48:42 +00:00
exit ;
2014-09-20 19:52:30 +00:00
}
2013-07-24 16:01:36 +00:00
2017-02-16 11:46:01 +00:00
if ( ! class_exists ( 'WC_Admin_Post_Types' , false ) ) :
2013-07-24 16:01:36 +00:00
/**
2015-11-03 12:28:01 +00:00
* WC_Admin_Post_Types Class .
2014-06-04 10:16:19 +00:00
*
* Handles the edit posts views and some functionality on the edit post screen for WC post types .
2013-07-24 16:01:36 +00:00
*/
class WC_Admin_Post_Types {
/**
2015-11-03 12:28:01 +00:00
* Constructor .
2014-06-04 10:16:19 +00:00
*/
public function __construct () {
add_filter ( 'post_updated_messages' , array ( $this , 'post_updated_messages' ) );
2015-02-08 14:40:19 +00:00
add_filter ( 'bulk_post_updated_messages' , array ( $this , 'bulk_post_updated_messages' ), 10 , 2 );
2015-02-08 15:45:08 +00:00
// Disable Auto Save
2014-06-04 10:16:19 +00:00
add_action ( 'admin_print_scripts' , array ( $this , 'disable_autosave' ) );
2017-01-04 15:18:02 +00:00
// Extra post data.
add_action ( 'edit_form_top' , array ( $this , 'edit_form_top' ) );
2014-06-04 10:16:19 +00:00
// WP List table columns. Defined here so they are always available for events such as inline editing.
2015-02-12 14:26:00 +00:00
add_filter ( 'manage_product_posts_columns' , array ( $this , 'product_columns' ) );
add_filter ( 'manage_shop_coupon_posts_columns' , array ( $this , 'shop_coupon_columns' ) );
add_filter ( 'manage_shop_order_posts_columns' , array ( $this , 'shop_order_columns' ) );
2014-06-12 07:59:45 +00:00
2014-06-04 10:16:19 +00:00
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' ) );
2015-07-27 19:14:41 +00:00
add_filter ( 'list_table_primary_column' , array ( $this , 'list_table_primary_column' ), 10 , 2 );
2017-06-22 16:10:52 +00:00
add_filter ( 'post_row_actions' , array ( $this , 'row_actions' ), 100 , 2 );
2015-07-27 19:14:41 +00:00
2014-12-15 20:49:18 +00:00
// Views
2017-05-16 14:05:11 +00:00
add_filter ( 'views_edit-product' , array ( $this , 'product_views' ) );
add_filter ( 'disable_months_dropdown' , array ( $this , 'disable_months_dropdown' ), 10 , 2 );
2014-06-04 10:16:19 +00:00
// 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 );
2016-11-16 20:48:42 +00:00
add_action ( 'save_post' , array ( $this , 'bulk_and_quick_edit_hook' ), 10 , 2 );
add_action ( 'woocommerce_product_bulk_and_quick_edit' , array ( $this , 'bulk_and_quick_edit_save_post' ), 10 , 2 );
2016-11-17 20:57:48 +00:00
add_filter ( 'bulk_actions-edit-shop_order' , array ( $this , 'shop_order_bulk_actions' ) );
2016-12-15 15:51:51 +00:00
add_filter ( 'handle_bulk_actions-edit-shop_order' , array ( $this , 'handle_shop_order_bulk_actions' ), 10 , 3 );
2014-06-04 10:16:19 +00:00
add_action ( 'admin_notices' , array ( $this , 'bulk_admin_notices' ) );
2014-06-12 07:59:45 +00:00
// Order Search
2014-06-04 10:16:19 +00:00
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' ) );
// Edit post screens
add_filter ( 'enter_title_here' , array ( $this , 'enter_title_here' ), 1 , 2 );
add_action ( 'edit_form_after_title' , array ( $this , 'edit_form_after_title' ) );
2015-08-21 21:07:05 +00:00
add_filter ( 'default_hidden_meta_boxes' , array ( $this , 'hidden_meta_boxes' ), 10 , 2 );
2014-06-04 10:16:19 +00:00
add_action ( 'post_submitbox_misc_actions' , array ( $this , 'product_data_visibility' ) );
// 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' );
}
2016-07-27 10:58:43 +00:00
include_once ( dirname ( __FILE__ ) . '/class-wc-admin-meta-boxes.php' );
2014-06-04 10:16:19 +00:00
2015-07-20 17:15:51 +00:00
// Disable DFW feature pointer
add_action ( 'admin_footer' , array ( $this , 'disable_dfw_feature_pointer' ) );
2015-10-01 08:52:00 +00:00
2016-02-19 19:04:36 +00:00
// Disable post type view mode options
add_filter ( 'view_mode_post_types' , array ( $this , 'disable_view_mode_options' ) );
2017-03-20 08:28:38 +00:00
// Update the screen options.
add_filter ( 'default_hidden_columns' , array ( $this , 'adjust_shop_order_columns' ), 10 , 2 );
2016-06-03 13:07:41 +00:00
// Show blank state
add_action ( 'manage_posts_extra_tablenav' , array ( $this , 'maybe_render_blank_state' ) );
2016-10-11 11:44:54 +00:00
// Hide template for CPT archive.
add_filter ( 'theme_page_templates' , array ( $this , 'hide_cpt_archive_templates' ), 10 , 3 );
add_action ( 'edit_form_top' , array ( $this , 'show_cpt_archive_notice' ) );
2017-06-28 04:38:09 +00:00
// Add a post display state for special WC pages.
add_filter ( 'display_post_states' , array ( $this , 'add_display_post_states' ), 10 , 2 );
2014-06-04 10:16:19 +00:00
}
2017-02-20 13:21:51 +00:00
/**
* Adjust shop order columns for the user on certain conditions .
2017-05-15 11:50:52 +00:00
*
* @ param array $hidden
* @ param object $screen
*
* @ return array
2017-02-20 13:21:51 +00:00
*/
2017-03-20 08:28:38 +00:00
public function adjust_shop_order_columns ( $hidden , $screen ) {
2017-03-20 16:25:30 +00:00
if ( isset ( $screen -> id ) && 'edit-shop_order' === $screen -> id ) {
if ( 'disabled' === get_option ( 'woocommerce_ship_to_countries' ) ) {
2017-03-20 08:28:38 +00:00
$hidden [] = 'shipping_address' ;
} else {
$hidden [] = 'billing_address' ;
}
2017-02-20 13:21:51 +00:00
}
2017-03-20 08:28:38 +00:00
return $hidden ;
2017-02-20 13:21:51 +00:00
}
2015-02-08 14:42:48 +00:00
/**
* Change messages when a post type is updated .
* @ param array $messages
* @ return array
*/
public function post_updated_messages ( $messages ) {
global $post , $post_ID ;
$messages [ 'product' ] = array (
0 => '' , // Unused. Messages start at index 1.
1 => sprintf ( __ ( 'Product updated. <a href="%s">View Product</a>' , 'woocommerce' ), esc_url ( get_permalink ( $post_ID ) ) ),
2 => __ ( 'Custom field updated.' , 'woocommerce' ),
3 => __ ( 'Custom field deleted.' , 'woocommerce' ),
4 => __ ( 'Product updated.' , 'woocommerce' ),
2016-10-29 10:16:03 +00:00
/* translators: %s: revision title */
2015-02-08 14:42:48 +00:00
5 => isset ( $_GET [ 'revision' ] ) ? sprintf ( __ ( 'Product restored to revision from %s' , 'woocommerce' ), wp_post_revision_title ( ( int ) $_GET [ 'revision' ], false ) ) : false ,
2016-10-29 10:16:03 +00:00
/* translators: %s: product url */
2015-02-08 14:42:48 +00:00
6 => sprintf ( __ ( 'Product published. <a href="%s">View Product</a>' , 'woocommerce' ), esc_url ( get_permalink ( $post_ID ) ) ),
7 => __ ( 'Product saved.' , 'woocommerce' ),
2016-10-29 10:16:03 +00:00
/* translators: %s: product url */
2016-10-12 10:16:30 +00:00
8 => sprintf ( __ ( 'Product submitted. <a target="_blank" href="%s">Preview product</a>' , 'woocommerce' ), esc_url ( add_query_arg ( 'preview' , 'true' , get_permalink ( $post_ID ) ) ) ),
2016-10-29 10:16:03 +00:00
/* translators: 1: date 2: product url */
2016-10-12 10:16:30 +00:00
9 => sprintf ( __ ( 'Product scheduled for: <strong>%1$s</strong>. <a target="_blank" href="%2$s">Preview product</a>' , 'woocommerce' ),
2015-02-08 14:42:48 +00:00
date_i18n ( __ ( 'M j, Y @ G:i' , 'woocommerce' ), strtotime ( $post -> post_date ) ), esc_url ( get_permalink ( $post_ID ) ) ),
2016-10-29 10:16:03 +00:00
/* translators: %s: product url */
2016-10-12 10:16:30 +00:00
10 => sprintf ( __ ( 'Product draft updated. <a target="_blank" href="%s">Preview product</a>' , 'woocommerce' ), esc_url ( add_query_arg ( 'preview' , 'true' , get_permalink ( $post_ID ) ) ) ),
2015-02-08 14:42:48 +00:00
);
$messages [ 'shop_order' ] = array (
0 => '' , // Unused. Messages start at index 1.
1 => __ ( 'Order updated.' , 'woocommerce' ),
2 => __ ( 'Custom field updated.' , 'woocommerce' ),
3 => __ ( 'Custom field deleted.' , 'woocommerce' ),
4 => __ ( 'Order updated.' , 'woocommerce' ),
2016-10-29 10:16:03 +00:00
/* translators: %s: revision title */
2015-02-08 14:42:48 +00:00
5 => isset ( $_GET [ 'revision' ] ) ? sprintf ( __ ( 'Order restored to revision from %s' , 'woocommerce' ), wp_post_revision_title ( ( int ) $_GET [ 'revision' ], false ) ) : false ,
6 => __ ( 'Order updated.' , 'woocommerce' ),
7 => __ ( 'Order saved.' , 'woocommerce' ),
8 => __ ( 'Order submitted.' , 'woocommerce' ),
2016-10-29 10:16:03 +00:00
/* translators: %s: date */
2015-02-08 14:42:48 +00:00
9 => sprintf ( __ ( 'Order scheduled for: <strong>%1$s</strong>.' , 'woocommerce' ),
date_i18n ( __ ( 'M j, Y @ G:i' , 'woocommerce' ), strtotime ( $post -> post_date ) ) ),
10 => __ ( 'Order draft updated.' , 'woocommerce' ),
2017-06-15 14:13:59 +00:00
11 => __ ( 'Order updated and sent to the customer.' , 'woocommerce' ),
2015-02-08 14:42:48 +00:00
);
$messages [ 'shop_coupon' ] = array (
0 => '' , // Unused. Messages start at index 1.
1 => __ ( 'Coupon updated.' , 'woocommerce' ),
2 => __ ( 'Custom field updated.' , 'woocommerce' ),
3 => __ ( 'Custom field deleted.' , 'woocommerce' ),
4 => __ ( 'Coupon updated.' , 'woocommerce' ),
2016-10-29 10:16:03 +00:00
/* translators: %s: revision title */
2015-02-08 14:42:48 +00:00
5 => isset ( $_GET [ 'revision' ] ) ? sprintf ( __ ( 'Coupon restored to revision from %s' , 'woocommerce' ), wp_post_revision_title ( ( int ) $_GET [ 'revision' ], false ) ) : false ,
6 => __ ( 'Coupon updated.' , 'woocommerce' ),
7 => __ ( 'Coupon saved.' , 'woocommerce' ),
8 => __ ( 'Coupon submitted.' , 'woocommerce' ),
2016-10-29 10:16:03 +00:00
/* translators: %s: date */
2015-02-08 14:42:48 +00:00
9 => sprintf ( __ ( 'Coupon scheduled for: <strong>%1$s</strong>.' , 'woocommerce' ),
date_i18n ( __ ( 'M j, Y @ G:i' , 'woocommerce' ), strtotime ( $post -> post_date ) ) ),
2016-08-27 01:46:45 +00:00
10 => __ ( 'Coupon draft updated.' , 'woocommerce' ),
2015-02-08 14:42:48 +00:00
);
return $messages ;
}
/**
2015-02-08 14:45:19 +00:00
* Specify custom bulk actions messages for different post types .
2015-02-08 14:42:48 +00:00
* @ param array $bulk_messages
* @ param array $bulk_counts
* @ return array
*/
public function bulk_post_updated_messages ( $bulk_messages , $bulk_counts ) {
$bulk_messages [ 'product' ] = array (
2016-10-29 10:16:03 +00:00
/* translators: %s: product count */
2015-07-13 14:03:03 +00:00
'updated' => _n ( '%s product updated.' , '%s products updated.' , $bulk_counts [ 'updated' ], 'woocommerce' ),
2016-10-29 10:16:03 +00:00
/* translators: %s: product count */
2015-07-13 14:03:03 +00:00
'locked' => _n ( '%s product not updated, somebody is editing it.' , '%s products not updated, somebody is editing them.' , $bulk_counts [ 'locked' ], 'woocommerce' ),
2016-10-29 10:16:03 +00:00
/* translators: %s: product count */
2015-07-13 14:03:03 +00:00
'deleted' => _n ( '%s product permanently deleted.' , '%s products permanently deleted.' , $bulk_counts [ 'deleted' ], 'woocommerce' ),
2016-10-29 10:16:03 +00:00
/* translators: %s: product count */
2015-07-13 14:03:03 +00:00
'trashed' => _n ( '%s product moved to the Trash.' , '%s products moved to the Trash.' , $bulk_counts [ 'trashed' ], 'woocommerce' ),
2016-10-29 10:16:03 +00:00
/* translators: %s: product count */
2015-07-13 14:03:03 +00:00
'untrashed' => _n ( '%s product restored from the Trash.' , '%s products restored from the Trash.' , $bulk_counts [ 'untrashed' ], 'woocommerce' ),
2015-02-08 14:42:48 +00:00
);
$bulk_messages [ 'shop_order' ] = array (
2016-10-29 10:16:03 +00:00
/* translators: %s: order count */
2015-07-13 14:03:03 +00:00
'updated' => _n ( '%s order updated.' , '%s orders updated.' , $bulk_counts [ 'updated' ], 'woocommerce' ),
2016-10-29 10:16:03 +00:00
/* translators: %s: order count */
2015-07-13 14:03:03 +00:00
'locked' => _n ( '%s order not updated, somebody is editing it.' , '%s orders not updated, somebody is editing them.' , $bulk_counts [ 'locked' ], 'woocommerce' ),
2016-10-29 10:16:03 +00:00
/* translators: %s: order count */
2015-07-13 14:03:03 +00:00
'deleted' => _n ( '%s order permanently deleted.' , '%s orders permanently deleted.' , $bulk_counts [ 'deleted' ], 'woocommerce' ),
2016-10-29 10:16:03 +00:00
/* translators: %s: order count */
2015-07-13 14:03:03 +00:00
'trashed' => _n ( '%s order moved to the Trash.' , '%s orders moved to the Trash.' , $bulk_counts [ 'trashed' ], 'woocommerce' ),
2016-10-29 10:16:03 +00:00
/* translators: %s: order count */
2015-07-13 14:03:03 +00:00
'untrashed' => _n ( '%s order restored from the Trash.' , '%s orders restored from the Trash.' , $bulk_counts [ 'untrashed' ], 'woocommerce' ),
2015-02-08 14:42:48 +00:00
);
$bulk_messages [ 'shop_coupon' ] = array (
2016-10-29 10:16:03 +00:00
/* translators: %s: coupon count */
2015-07-13 14:03:03 +00:00
'updated' => _n ( '%s coupon updated.' , '%s coupons updated.' , $bulk_counts [ 'updated' ], 'woocommerce' ),
2016-10-29 10:16:03 +00:00
/* translators: %s: coupon count */
2015-07-13 14:03:03 +00:00
'locked' => _n ( '%s coupon not updated, somebody is editing it.' , '%s coupons not updated, somebody is editing them.' , $bulk_counts [ 'locked' ], 'woocommerce' ),
2016-10-29 10:16:03 +00:00
/* translators: %s: coupon count */
2015-07-13 14:03:03 +00:00
'deleted' => _n ( '%s coupon permanently deleted.' , '%s coupons permanently deleted.' , $bulk_counts [ 'deleted' ], 'woocommerce' ),
2016-10-29 10:16:03 +00:00
/* translators: %s: coupon count */
2015-07-13 14:03:03 +00:00
'trashed' => _n ( '%s coupon moved to the Trash.' , '%s coupons moved to the Trash.' , $bulk_counts [ 'trashed' ], 'woocommerce' ),
2016-10-29 10:16:03 +00:00
/* translators: %s: coupon count */
2015-07-13 14:03:03 +00:00
'untrashed' => _n ( '%s coupon restored from the Trash.' , '%s coupons restored from the Trash.' , $bulk_counts [ 'untrashed' ], 'woocommerce' ),
2015-02-08 14:42:48 +00:00
);
return $bulk_messages ;
}
2014-06-04 10:16:19 +00:00
/**
2015-11-03 12:28:01 +00:00
* Define custom columns for products .
2014-06-04 10:16:19 +00:00
* @ 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" />' ;
2015-08-05 19:17:52 +00:00
$columns [ 'thumb' ] = '<span class="wc-image tips" data-tip="' . esc_attr__ ( 'Image' , 'woocommerce' ) . '">' . __ ( 'Image' , 'woocommerce' ) . '</span>' ;
2014-06-04 10:16:19 +00:00
$columns [ 'name' ] = __ ( 'Name' , 'woocommerce' );
if ( wc_product_sku_enabled () ) {
$columns [ 'sku' ] = __ ( 'SKU' , 'woocommerce' );
}
2016-01-27 13:00:50 +00:00
if ( 'yes' === get_option ( 'woocommerce_manage_stock' ) ) {
2014-06-04 10:16:19 +00:00
$columns [ 'is_in_stock' ] = __ ( 'Stock' , 'woocommerce' );
}
$columns [ 'price' ] = __ ( 'Price' , 'woocommerce' );
$columns [ 'product_cat' ] = __ ( 'Categories' , 'woocommerce' );
$columns [ 'product_tag' ] = __ ( 'Tags' , 'woocommerce' );
2015-08-05 19:17:52 +00:00
$columns [ 'featured' ] = '<span class="wc-featured parent-tips" data-tip="' . esc_attr__ ( 'Featured' , 'woocommerce' ) . '">' . __ ( 'Featured' , 'woocommerce' ) . '</span>' ;
$columns [ 'product_type' ] = '<span class="wc-type parent-tips" data-tip="' . esc_attr__ ( 'Type' , 'woocommerce' ) . '">' . __ ( 'Type' , 'woocommerce' ) . '</span>' ;
2014-06-04 10:16:19 +00:00
$columns [ 'date' ] = __ ( 'Date' , 'woocommerce' );
return array_merge ( $columns , $existing_columns );
2014-12-21 05:48:30 +00:00
2014-06-04 10:16:19 +00:00
}
/**
2015-11-03 12:28:01 +00:00
* Define custom columns for coupons .
2014-06-04 10:16:19 +00:00
* @ param array $existing_columns
* @ return array
*/
public function shop_coupon_columns ( $existing_columns ) {
$columns = array ();
2014-11-19 23:36:47 +00:00
$columns [ 'cb' ] = $existing_columns [ 'cb' ];
$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' );
2014-06-04 10:16:19 +00:00
return $columns ;
}
/**
2015-11-03 12:28:01 +00:00
* Define custom columns for orders .
2014-06-04 10:16:19 +00:00
* @ param array $existing_columns
* @ return array
*/
public function shop_order_columns ( $existing_columns ) {
$columns = array ();
2014-11-19 23:36:47 +00:00
$columns [ 'cb' ] = $existing_columns [ 'cb' ];
2014-06-04 10:16:19 +00:00
$columns [ 'order_status' ] = '<span class="status_head tips" data-tip="' . esc_attr__ ( 'Status' , 'woocommerce' ) . '">' . esc_attr__ ( 'Status' , 'woocommerce' ) . '</span>' ;
$columns [ 'order_title' ] = __ ( 'Order' , 'woocommerce' );
2015-10-01 08:52:00 +00:00
$columns [ 'billing_address' ] = __ ( 'Billing' , 'woocommerce' );
2014-06-04 10:16:19 +00:00
$columns [ 'shipping_address' ] = __ ( 'Ship to' , 'woocommerce' );
2016-10-12 10:16:30 +00:00
$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>' ;
2014-06-04 10:16:19 +00:00
$columns [ 'order_date' ] = __ ( 'Date' , 'woocommerce' );
$columns [ 'order_total' ] = __ ( 'Total' , 'woocommerce' );
$columns [ 'order_actions' ] = __ ( 'Actions' , 'woocommerce' );
return $columns ;
}
/**
2017-07-10 05:56:28 +00:00
* Output custom columns for products .
2015-07-27 19:14:41 +00:00
*
* @ param string $column
2014-06-04 10:16:19 +00:00
*/
public function render_product_columns ( $column ) {
2015-05-18 05:06:26 +00:00
global $post , $the_product ;
2014-06-04 10:16:19 +00:00
2016-11-02 18:50:42 +00:00
if ( empty ( $the_product ) || $the_product -> get_id () != $post -> ID ) {
2014-08-19 10:09:29 +00:00
$the_product = wc_get_product ( $post );
2014-06-04 10:16:19 +00:00
}
2017-03-24 15:02:51 +00:00
// Only continue if we have a product.
if ( empty ( $the_product ) ) {
return ;
}
2014-06-04 10:16:19 +00:00
switch ( $column ) {
case 'thumb' :
2016-01-04 10:46:11 +00:00
echo '<a href="' . get_edit_post_link ( $post -> ID ) . '">' . $the_product -> get_image ( 'thumbnail' ) . '</a>' ;
2014-06-04 10:16:19 +00:00
break ;
case 'name' :
2015-07-27 19:14:41 +00:00
$edit_link = get_edit_post_link ( $post -> ID );
$title = _draft_or_post_title ();
2014-06-04 10:16:19 +00:00
2015-10-06 04:55:11 +00:00
echo '<strong><a class="row-title" href="' . esc_url ( $edit_link ) . '">' . esc_html ( $title ) . '</a>' ;
2014-06-04 10:16:19 +00:00
_post_states ( $post );
echo '</strong>' ;
if ( $post -> post_parent > 0 ) {
2016-09-01 20:50:14 +00:00
echo ' ← <a href="' . get_edit_post_link ( $post -> post_parent ) . '">' . get_the_title ( $post -> post_parent ) . '</a>' ;
2014-06-04 10:16:19 +00:00
}
// Excerpt view
if ( isset ( $_GET [ 'mode' ] ) && 'excerpt' == $_GET [ 'mode' ] ) {
echo apply_filters ( 'the_excerpt' , $post -> post_excerpt );
}
get_inline_data ( $post );
2015-11-03 12:28:01 +00:00
/* Custom inline data for woocommerce. */
2014-06-04 10:16:19 +00:00
echo '
2017-01-06 12:45:26 +00:00
< div class = " hidden " id = " woocommerce_inline_' . absint( $post->ID ) . ' " >
< div class = " menu_order " > ' . absint( $the_product->get_menu_order() ) . ' </ div >
< div class = " sku " > ' . esc_html( $the_product->get_sku() ) . ' </ div >
< div class = " regular_price " > ' . esc_html( $the_product->get_regular_price() ) . ' </ div >
< div class = " sale_price " > ' . esc_html( $the_product->get_sale_price() ) . ' </ div >
< div class = " weight " > ' . esc_html( $the_product->get_weight() ) . ' </ div >
< div class = " length " > ' . esc_html( $the_product->get_length() ) . ' </ div >
< div class = " width " > ' . esc_html( $the_product->get_width() ) . ' </ div >
< div class = " height " > ' . esc_html( $the_product->get_height() ) . ' </ div >
< div class = " shipping_class " > ' . esc_html( $the_product->get_shipping_class() ) . ' </ div >
< div class = " visibility " > ' . esc_html( $the_product->get_catalog_visibility() ) . ' </ div >
< div class = " stock_status " > ' . esc_html( $the_product->get_stock_status() ) . ' </ div >
< div class = " stock " > ' . esc_html( $the_product->get_stock_quantity() ) . ' </ div >
2017-01-16 17:59:56 +00:00
< div class = " manage_stock " > ' . esc_html( wc_bool_to_string( $the_product->get_manage_stock() ) ) . ' </ div >
< div class = " featured " > ' . esc_html( wc_bool_to_string( $the_product->get_featured() ) ) . ' </ div >
2017-01-06 12:45:26 +00:00
< div class = " product_type " > ' . esc_html( $the_product->get_type() ) . ' </ div >
2017-01-16 17:59:56 +00:00
< div class = " product_is_virtual " > ' . esc_html( wc_bool_to_string( $the_product->get_virtual() ) ) . ' </ div >
2017-01-06 12:45:26 +00:00
< div class = " tax_status " > ' . esc_html( $the_product->get_tax_status() ) . ' </ div >
< div class = " tax_class " > ' . esc_html( $the_product->get_tax_class() ) . ' </ div >
< div class = " backorders " > ' . esc_html( $the_product->get_backorders() ) . ' </ div >
2014-06-04 10:16:19 +00:00
</ div >
' ;
break ;
case 'sku' :
2017-01-06 12:45:26 +00:00
echo $the_product -> get_sku () ? esc_html ( $the_product -> get_sku () ) : '<span class="na">–</span>' ;
2014-06-04 10:16:19 +00:00
break ;
case 'product_type' :
2016-11-09 12:26:46 +00:00
if ( $the_product -> is_type ( 'grouped' ) ) {
2015-08-05 19:17:52 +00:00
echo '<span class="product-type tips grouped" data-tip="' . esc_attr__ ( 'Grouped' , 'woocommerce' ) . '"></span>' ;
2016-11-09 12:26:46 +00:00
} elseif ( $the_product -> is_type ( 'external' ) ) {
echo '<span class="product-type tips external" data-tip="' . esc_attr__ ( 'External/Affiliate' , 'woocommerce' ) . '"></span>' ;
} elseif ( $the_product -> is_type ( 'simple' ) ) {
2014-06-04 10:16:19 +00:00
if ( $the_product -> is_virtual () ) {
2015-08-05 19:17:52 +00:00
echo '<span class="product-type tips virtual" data-tip="' . esc_attr__ ( 'Virtual' , 'woocommerce' ) . '"></span>' ;
2014-06-04 10:16:19 +00:00
} elseif ( $the_product -> is_downloadable () ) {
2015-08-05 19:17:52 +00:00
echo '<span class="product-type tips downloadable" data-tip="' . esc_attr__ ( 'Downloadable' , 'woocommerce' ) . '"></span>' ;
2014-06-04 10:16:19 +00:00
} else {
2015-08-05 19:17:52 +00:00
echo '<span class="product-type tips simple" data-tip="' . esc_attr__ ( 'Simple' , 'woocommerce' ) . '"></span>' ;
2014-06-04 10:16:19 +00:00
}
2016-11-09 12:26:46 +00:00
} elseif ( $the_product -> is_type ( 'variable' ) ) {
2015-08-05 19:17:52 +00:00
echo '<span class="product-type tips variable" data-tip="' . esc_attr__ ( 'Variable' , 'woocommerce' ) . '"></span>' ;
2014-06-04 10:16:19 +00:00
} else {
// Assuming that we have other types in future
2017-02-16 15:59:24 +00:00
echo '<span class="product-type tips ' . esc_attr ( sanitize_html_class ( $the_product -> get_type () ) ) . '" data-tip="' . esc_attr ( ucfirst ( $the_product -> get_type () ) ) . '"></span>' ;
2014-06-04 10:16:19 +00:00
}
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 {
2014-11-19 19:01:06 +00:00
$termlist = array ();
2014-06-04 10:16:19 +00:00
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' );
2016-11-04 15:41:51 +00:00
echo '<a href="' . esc_url ( $url ) . '" aria-label="' . __ ( 'Toggle featured' , 'woocommerce' ) . '">' ;
2014-06-04 10:16:19 +00:00
if ( $the_product -> is_featured () ) {
2015-08-05 19:17:52 +00:00
echo '<span class="wc-featured tips" data-tip="' . esc_attr__ ( 'Yes' , 'woocommerce' ) . '">' . __ ( 'Yes' , 'woocommerce' ) . '</span>' ;
2014-06-04 10:16:19 +00:00
} else {
2015-08-05 19:17:52 +00:00
echo '<span class="wc-featured not-featured tips" data-tip="' . esc_attr__ ( 'No' , 'woocommerce' ) . '">' . __ ( 'No' , 'woocommerce' ) . '</span>' ;
2014-06-04 10:16:19 +00:00
}
echo '</a>' ;
break ;
case 'is_in_stock' :
2016-06-01 12:06:10 +00:00
2014-06-04 10:16:19 +00:00
if ( $the_product -> is_in_stock () ) {
2016-06-01 12:06:10 +00:00
$stock_html = '<mark class="instock">' . __ ( 'In stock' , 'woocommerce' ) . '</mark>' ;
2014-06-04 10:16:19 +00:00
} else {
2016-06-01 12:06:10 +00:00
$stock_html = '<mark class="outofstock">' . __ ( 'Out of stock' , 'woocommerce' ) . '</mark>' ;
2014-06-04 10:16:19 +00:00
}
2016-11-02 18:50:42 +00:00
if ( $the_product -> managing_stock () ) {
2017-04-04 12:35:28 +00:00
$stock_html .= ' (' . wc_stock_amount ( $the_product -> get_stock_quantity () ) . ')' ;
2014-06-04 10:16:19 +00:00
}
2016-06-01 12:06:10 +00:00
echo apply_filters ( 'woocommerce_admin_stock_html' , $stock_html , $the_product );
2014-06-04 10:16:19 +00:00
break ;
default :
break ;
}
}
2015-07-27 19:14:41 +00:00
/**
2015-11-03 12:28:01 +00:00
* Output custom columns for coupons .
2015-07-27 19:14:41 +00:00
*
* @ param string $column
*/
public function render_shop_coupon_columns ( $column ) {
2017-02-22 17:29:59 +00:00
global $post , $the_coupon ;
if ( empty ( $the_coupon ) || $the_coupon -> get_id () !== $post -> ID ) {
$the_coupon = new WC_Coupon ( $post -> ID );
}
2014-06-04 10:16:19 +00:00
2015-07-27 19:14:41 +00:00
switch ( $column ) {
case 'coupon_code' :
$edit_link = get_edit_post_link ( $post -> ID );
2017-02-22 17:29:59 +00:00
$title = $the_coupon -> get_code ();
2014-06-04 10:16:19 +00:00
2015-10-06 04:55:11 +00:00
echo '<strong><a class="row-title" href="' . esc_url ( $edit_link ) . '">' . esc_html ( $title ) . '</a>' ;
2015-07-27 19:14:41 +00:00
_post_states ( $post );
2015-10-05 23:30:03 +00:00
echo '</strong>' ;
2014-06-04 10:16:19 +00:00
break ;
2014-11-19 23:36:47 +00:00
case 'type' :
2017-02-22 17:29:59 +00:00
echo esc_html ( wc_get_coupon_type ( $the_coupon -> get_discount_type () ) );
2014-06-04 10:16:19 +00:00
break ;
2014-11-19 23:36:47 +00:00
case 'amount' :
2017-02-22 21:58:32 +00:00
echo esc_html ( wc_format_localized_price ( $the_coupon -> get_amount () ) );
2014-06-04 10:16:19 +00:00
break ;
2014-11-19 23:36:47 +00:00
case 'products' :
2017-02-22 17:29:59 +00:00
$product_ids = $the_coupon -> get_product_ids ();
2014-11-30 06:52:32 +00:00
2014-11-19 23:36:47 +00:00
if ( sizeof ( $product_ids ) > 0 ) {
2014-06-04 10:16:19 +00:00
echo esc_html ( implode ( ', ' , $product_ids ) );
2014-11-19 23:36:47 +00:00
} else {
2014-06-04 10:16:19 +00:00
echo '–' ;
2014-11-19 23:36:47 +00:00
}
2014-06-04 10:16:19 +00:00
break ;
2014-11-19 23:36:47 +00:00
case 'usage_limit' :
2017-02-22 17:29:59 +00:00
$usage_limit = $the_coupon -> get_usage_limit ();
2014-06-04 10:16:19 +00:00
2014-11-19 23:36:47 +00:00
if ( $usage_limit ) {
2014-06-04 10:16:19 +00:00
echo esc_html ( $usage_limit );
2014-11-19 23:36:47 +00:00
} else {
2014-06-04 10:16:19 +00:00
echo '–' ;
2014-11-19 23:36:47 +00:00
}
2014-06-04 10:16:19 +00:00
break ;
2014-11-19 23:36:47 +00:00
case 'usage' :
2017-02-22 17:29:59 +00:00
$usage_count = $the_coupon -> get_usage_count ();
$usage_limit = $the_coupon -> get_usage_limit ();
2014-06-04 10:16:19 +00:00
2016-10-24 07:31:07 +00:00
/* translators: 1: count 2: limit */
printf (
__ ( '%1$s / %2$s' , 'woocommerce' ),
2017-03-13 16:48:28 +00:00
esc_html ( $usage_count ),
2017-02-22 17:29:59 +00:00
esc_html ( $usage_limit ? $usage_limit : '∞' )
2016-10-24 07:31:07 +00:00
);
2014-06-04 10:16:19 +00:00
break ;
2014-11-19 23:36:47 +00:00
case 'expiry_date' :
2017-02-22 17:29:59 +00:00
$expiry_date = $the_coupon -> get_date_expires ();
2014-06-04 10:16:19 +00:00
2014-11-19 23:36:47 +00:00
if ( $expiry_date ) {
2017-03-14 17:27:48 +00:00
echo esc_html ( $expiry_date -> date_i18n ( 'F j, Y' ) );
2014-11-19 23:36:47 +00:00
} else {
2014-06-04 10:16:19 +00:00
echo '–' ;
2014-11-19 23:36:47 +00:00
}
2014-06-04 10:16:19 +00:00
break ;
2014-11-19 23:36:47 +00:00
case 'description' :
2017-02-22 17:29:59 +00:00
echo wp_kses_post ( $the_coupon -> get_description () ? $the_coupon -> get_description () : '–' );
2014-06-04 10:16:19 +00:00
break ;
}
}
/**
2015-11-03 12:28:01 +00:00
* Output custom columns for coupons .
2016-02-05 20:01:21 +00:00
* @ param string $column
2014-06-04 10:16:19 +00:00
*/
public function render_shop_order_columns ( $column ) {
2017-01-11 15:31:31 +00:00
global $post , $the_order ;
2014-06-04 10:16:19 +00:00
2017-02-09 12:29:16 +00:00
if ( empty ( $the_order ) || $the_order -> get_id () !== $post -> ID ) {
2014-08-15 12:29:21 +00:00
$the_order = wc_get_order ( $post -> ID );
2014-06-04 10:16:19 +00:00
}
switch ( $column ) {
case 'order_status' :
2017-02-16 15:59:24 +00:00
printf ( '<mark class="%s tips" data-tip="%s">%s</mark>' , esc_attr ( sanitize_html_class ( $the_order -> get_status () ) ), esc_attr ( wc_get_order_status_name ( $the_order -> get_status () ) ), esc_html ( wc_get_order_status_name ( $the_order -> get_status () ) ) );
2014-06-04 10:16:19 +00:00
break ;
case 'order_date' :
2017-08-03 06:48:17 +00:00
printf (
'<time datetime="%1$s" title="%2$s">%3$s</time>' ,
esc_attr ( $the_order -> get_date_created () -> date ( 'c' ) ),
esc_html ( $the_order -> get_date_created () -> date_i18n ( get_option ( 'date_format' ) . ' ' . get_option ( 'time_format' ) ) ),
esc_html ( $the_order -> get_date_created () -> date_i18n ( apply_filters ( 'woocommerce_admin_order_date_format' , get_option ( 'date_format' ) ) ) )
);
2014-06-04 10:16:19 +00:00
break ;
case 'customer_message' :
2016-08-05 14:59:32 +00:00
if ( $the_order -> get_customer_note () ) {
echo '<span class="note-on tips" data-tip="' . wc_sanitize_tooltip ( $the_order -> get_customer_note () ) . '">' . __ ( 'Yes' , 'woocommerce' ) . '</span>' ;
2014-12-04 15:57:12 +00:00
} else {
2014-06-04 10:16:19 +00:00
echo '<span class="na">–</span>' ;
2014-12-04 15:57:12 +00:00
}
2014-06-04 10:16:19 +00:00
break ;
2015-10-01 08:52:00 +00:00
case 'billing_address' :
if ( $address = $the_order -> get_formatted_billing_address () ) {
echo esc_html ( preg_replace ( '#<br\s*/?>#i' , ', ' , $address ) );
} else {
echo '–' ;
}
2016-08-05 15:09:04 +00:00
if ( $the_order -> get_billing_phone () ) {
2016-10-11 01:39:13 +00:00
echo '<small class="meta">' . __ ( 'Phone:' , 'woocommerce' ) . ' ' . esc_html ( $the_order -> get_billing_phone () ) . '</small>' ;
2015-10-01 08:52:00 +00:00
}
break ;
2014-06-04 10:16:19 +00:00
case 'shipping_address' :
2014-11-30 06:52:32 +00:00
2015-01-20 13:31:02 +00:00
if ( $address = $the_order -> get_formatted_shipping_address () ) {
2016-09-01 20:50:14 +00:00
echo '<a target="_blank" href="' . esc_url ( $the_order -> get_shipping_address_map_url () ) . '">' . esc_html ( preg_replace ( '#<br\s*/?>#i' , ', ' , $address ) ) . '</a>' ;
2014-11-30 06:52:32 +00:00
} else {
2014-06-04 10:16:19 +00:00
echo '–' ;
2014-11-30 06:52:32 +00:00
}
2014-06-04 10:16:19 +00:00
2014-11-30 06:52:32 +00:00
if ( $the_order -> get_shipping_method () ) {
2014-06-04 10:16:19 +00:00
echo '<small class="meta">' . __ ( 'Via' , 'woocommerce' ) . ' ' . esc_html ( $the_order -> get_shipping_method () ) . '</small>' ;
2014-11-30 06:52:32 +00:00
}
2014-06-04 10:16:19 +00:00
break ;
case 'order_notes' :
if ( $post -> comment_count ) {
2017-07-13 22:33:20 +00:00
$latest_notes = wc_get_order_notes ( array (
'order_id' => $post -> ID ,
'limit' => 1 ,
'orderby' => 'date_created_gmt' ,
2014-06-04 10:16:19 +00:00
) );
$latest_note = current ( $latest_notes );
2017-07-13 22:33:20 +00:00
if ( isset ( $latest_note -> content ) && 1 == $post -> comment_count ) {
echo '<span class="note-on tips" data-tip="' . wc_sanitize_tooltip ( $latest_note -> content ) . '">' . __ ( 'Yes' , 'woocommerce' ) . '</span>' ;
} elseif ( isset ( $latest_note -> content ) ) {
2016-10-29 10:16:03 +00:00
/* translators: %d: notes count */
2017-07-13 22:33:20 +00:00
echo '<span class="note-on tips" data-tip="' . wc_sanitize_tooltip ( $latest_note -> content . '<br/><small style="display:block">' . sprintf ( _n ( 'Plus %d other note' , 'Plus %d other notes' , ( $post -> comment_count - 1 ), 'woocommerce' ), $post -> comment_count - 1 ) . '</small>' ) . '">' . __ ( 'Yes' , 'woocommerce' ) . '</span>' ;
2014-06-04 10:16:19 +00:00
} else {
2016-10-29 10:16:03 +00:00
/* translators: %d: notes count */
2015-05-21 23:03:57 +00:00
echo '<span class="note-on tips" data-tip="' . wc_sanitize_tooltip ( sprintf ( _n ( '%d note' , '%d notes' , $post -> comment_count , 'woocommerce' ), $post -> comment_count ) ) . '">' . __ ( 'Yes' , 'woocommerce' ) . '</span>' ;
2014-06-04 10:16:19 +00:00
}
} else {
echo '<span class="na">–</span>' ;
}
break ;
case 'order_total' :
2015-09-07 21:30:55 +00:00
echo $the_order -> get_formatted_order_total ();
2014-06-04 10:16:19 +00:00
2016-08-05 14:59:55 +00:00
if ( $the_order -> get_payment_method_title () ) {
echo '<small class="meta">' . __ ( 'Via' , 'woocommerce' ) . ' ' . esc_html ( $the_order -> get_payment_method_title () ) . '</small>' ;
2014-06-04 10:16:19 +00:00
}
break ;
case 'order_title' :
2017-02-09 12:29:16 +00:00
if ( $the_order -> get_customer_id () ) {
$user = get_user_by ( 'id' , $the_order -> get_customer_id () );
$username = '<a href="user-edit.php?user_id=' . absint ( $the_order -> get_customer_id () ) . '">' ;
$username .= esc_html ( ucwords ( $user -> display_name ) );
2014-06-04 10:16:19 +00:00
$username .= '</a>' ;
2017-02-09 12:29:16 +00:00
} elseif ( $the_order -> get_billing_first_name () || $the_order -> get_billing_last_name () ) {
/* translators: 1: first name 2: last name */
$username = trim ( sprintf ( _x ( '%1$s %2$s' , 'full name' , 'woocommerce' ), $the_order -> get_billing_first_name (), $the_order -> get_billing_last_name () ) );
} elseif ( $the_order -> get_billing_company () ) {
$username = trim ( $the_order -> get_billing_company () );
2014-06-04 10:16:19 +00:00
} else {
2017-02-09 12:29:16 +00:00
$username = __ ( 'Guest' , 'woocommerce' );
2014-06-04 10:16:19 +00:00
}
2016-10-24 07:31:07 +00:00
/* translators: 1: order and number (i.e. Order #13) 2: user name */
printf (
__ ( '%1$s by %2$s' , 'woocommerce' ),
'<a href="' . admin_url ( 'post.php?post=' . absint ( $post -> ID ) . '&action=edit' ) . '" class="row-title"><strong>#' . esc_attr ( $the_order -> get_order_number () ) . '</strong></a>' ,
$username
);
2014-06-04 10:16:19 +00:00
2016-08-05 14:57:40 +00:00
if ( $the_order -> get_billing_email () ) {
echo '<small class="meta email"><a href="' . esc_url ( 'mailto:' . $the_order -> get_billing_email () ) . '">' . esc_html ( $the_order -> get_billing_email () ) . '</a></small>' ;
2014-06-04 10:16:19 +00:00
}
2015-09-07 11:34:42 +00:00
echo '<button type="button" class="toggle-row"><span class="screen-reader-text">' . __ ( 'Show more details' , 'woocommerce' ) . '</span></button>' ;
2014-06-04 10:16:19 +00:00
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 (
2014-11-30 06:52:32 +00:00
'url' => wp_nonce_url ( admin_url ( 'admin-ajax.php?action=woocommerce_mark_order_status&status=processing&order_id=' . $post -> ID ), 'woocommerce-mark-order-status' ),
'name' => __ ( 'Processing' , 'woocommerce' ),
2016-08-27 01:46:45 +00:00
'action' => " processing " ,
2014-06-04 10:16:19 +00:00
);
}
if ( $the_order -> has_status ( array ( 'pending' , 'on-hold' , 'processing' ) ) ) {
$actions [ 'complete' ] = array (
2014-11-30 06:52:32 +00:00
'url' => wp_nonce_url ( admin_url ( 'admin-ajax.php?action=woocommerce_mark_order_status&status=completed&order_id=' . $post -> ID ), 'woocommerce-mark-order-status' ),
'name' => __ ( 'Complete' , 'woocommerce' ),
2016-08-27 01:46:45 +00:00
'action' => " complete " ,
2014-06-04 10:16:19 +00:00
);
}
$actions [ 'view' ] = array (
2014-11-30 06:52:32 +00:00
'url' => admin_url ( 'post.php?post=' . $post -> ID . '&action=edit' ),
'name' => __ ( 'View' , 'woocommerce' ),
2016-08-27 01:46:45 +00:00
'action' => " view " ,
2014-06-04 10:16:19 +00:00
);
$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 ;
}
}
/**
2015-11-03 12:28:01 +00:00
* Make columns sortable - https :// gist . github . com / 906872.
2014-06-04 10:16:19 +00:00
*
2016-02-05 20:01:21 +00:00
* @ param array $columns
2014-06-04 10:16:19 +00:00
* @ return array
*/
public function product_sortable_columns ( $columns ) {
$custom = array (
'price' => 'price' ,
'sku' => 'sku' ,
2016-08-27 01:46:45 +00:00
'name' => 'title' ,
2014-06-04 10:16:19 +00:00
);
return wp_parse_args ( $custom , $columns );
}
/**
2015-11-03 12:28:01 +00:00
* Make columns sortable - https :// gist . github . com / 906872.
2014-06-04 10:16:19 +00:00
*
2016-02-05 20:01:21 +00:00
* @ param array $columns
2014-06-04 10:16:19 +00:00
* @ return array
*/
public function shop_coupon_sortable_columns ( $columns ) {
return $columns ;
}
/**
2015-11-03 12:28:01 +00:00
* Make columns sortable - https :// gist . github . com / 906872.
2014-06-04 10:16:19 +00:00
*
2016-02-05 20:01:21 +00:00
* @ param array $columns
2014-06-04 10:16:19 +00:00
* @ return array
*/
public function shop_order_sortable_columns ( $columns ) {
$custom = array (
'order_title' => 'ID' ,
'order_total' => 'order_total' ,
2016-08-27 01:46:45 +00:00
'order_date' => 'date' ,
2014-06-04 10:16:19 +00:00
);
unset ( $columns [ 'comments' ] );
return wp_parse_args ( $custom , $columns );
2014-06-12 07:59:45 +00:00
}
2014-06-04 10:16:19 +00:00
2015-07-27 19:14:41 +00:00
/**
2015-11-03 12:28:01 +00:00
* Set list table primary column for products and orders .
* Support for WordPress 4.3 .
2015-07-27 19:14:41 +00:00
*
* @ param string $default
* @ param string $screen_id
*
* @ return string
*/
public function list_table_primary_column ( $default , $screen_id ) {
if ( 'edit-product' === $screen_id ) {
return 'name' ;
}
if ( 'edit-shop_order' === $screen_id ) {
return 'order_title' ;
}
if ( 'edit-shop_coupon' === $screen_id ) {
return 'coupon_code' ;
}
return $default ;
}
/**
2015-11-03 12:28:01 +00:00
* Set row actions for products and orders .
2015-07-27 19:14:41 +00:00
*
* @ param array $actions
* @ param WP_Post $post
*
* @ return array
*/
public function row_actions ( $actions , $post ) {
if ( 'product' === $post -> post_type ) {
return array_merge ( array ( 'id' => 'ID: ' . $post -> ID ), $actions );
}
2016-02-05 20:01:21 +00:00
if ( in_array ( $post -> post_type , array ( 'shop_order' , 'shop_coupon' ) ) ) {
2015-07-27 19:14:41 +00:00
if ( isset ( $actions [ 'inline hide-if-no-js' ] ) ) {
unset ( $actions [ 'inline hide-if-no-js' ] );
}
}
return $actions ;
}
2014-06-04 10:16:19 +00:00
/**
2017-05-16 14:05:11 +00:00
* Change views on the edit product screen .
2014-06-04 10:16:19 +00:00
*
2016-02-05 20:01:21 +00:00
* @ param array $views
2014-06-04 10:16:19 +00:00
* @ return array
*/
2017-05-16 14:05:11 +00:00
public function product_views ( $views ) {
global $wp_query ;
2014-06-04 10:16:19 +00:00
2017-05-16 14:05:11 +00:00
// Products do not have authors.
unset ( $views [ 'mine' ] );
2014-06-04 10:16:19 +00:00
2017-05-16 14:05:11 +00:00
// Add sorting link.
if ( current_user_can ( 'edit_others_pages' ) ) {
$class = ( isset ( $wp_query -> query [ 'orderby' ] ) && 'menu_order title' === $wp_query -> query [ 'orderby' ] ) ? '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="' . esc_url ( $query_string ) . '" class="' . esc_attr ( $class ) . '">' . __ ( 'Sorting' , 'woocommerce' ) . '</a>' ;
}
2014-06-04 10:16:19 +00:00
return $views ;
}
2017-05-16 14:05:11 +00:00
/**
* @ deprecated 3.1
*/
public function product_sorting_link ( $views ) {
$this -> product_views ( $views );
}
/**
* Disable months dropdown on product screen .
*/
public function disable_months_dropdown ( $bool , $post_type ) {
return 'product' === $post_type ? true : $bool ;
}
2014-06-04 10:16:19 +00:00
/**
2015-11-03 12:28:01 +00:00
* Custom bulk edit - form .
2014-06-04 10:16:19 +00:00
*
* @ param mixed $column_name
* @ param mixed $post_type
*/
public function bulk_edit ( $column_name , $post_type ) {
2014-11-30 06:52:32 +00:00
2014-06-04 10:16:19 +00:00
if ( 'price' != $column_name || 'product' != $post_type ) {
return ;
}
2014-11-04 19:49:15 +00:00
$shipping_class = get_terms ( 'product_shipping_class' , array (
'hide_empty' => false ,
) );
2014-06-04 10:16:19 +00:00
include ( WC () -> plugin_path () . '/includes/admin/views/html-bulk-edit-product.php' );
}
/**
2015-11-03 12:28:01 +00:00
* Custom quick edit - form .
2014-06-04 10:16:19 +00:00
*
* @ param mixed $column_name
* @ param mixed $post_type
*/
public function quick_edit ( $column_name , $post_type ) {
2014-11-30 06:52:32 +00:00
2014-06-04 10:16:19 +00:00
if ( 'price' != $column_name || 'product' != $post_type ) {
return ;
}
2014-11-04 19:49:15 +00:00
$shipping_class = get_terms ( 'product_shipping_class' , array (
'hide_empty' => false ,
) );
2014-06-04 10:16:19 +00:00
include ( WC () -> plugin_path () . '/includes/admin/views/html-quick-edit-product.php' );
}
2016-11-16 20:48:42 +00:00
/**
* Offers a way to hook into save post without causing an infinite loop
* when quick / bulk saving product info .
*
2017-03-15 16:36:53 +00:00
* @ since 3.0 . 0
2016-11-16 20:48:42 +00:00
* @ param int $post_id
* @ param object $post
*/
public function bulk_and_quick_edit_hook ( $post_id , $post ) {
remove_action ( 'save_post' , array ( $this , 'bulk_and_quick_edit_hook' ) );
do_action ( 'woocommerce_product_bulk_and_quick_edit' , $post_id , $post );
add_action ( 'save_post' , array ( $this , 'bulk_and_quick_edit_hook' ), 10 , 2 );
}
2014-06-04 10:16:19 +00:00
/**
2015-11-03 12:28:01 +00:00
* Quick and bulk edit saving .
2014-06-04 10:16:19 +00:00
*
* @ 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
2014-08-19 10:09:29 +00:00
$product = wc_get_product ( $post );
2014-06-04 10:16:19 +00:00
if ( ! empty ( $_REQUEST [ 'woocommerce_quick_edit' ] ) ) {
$this -> quick_edit_save ( $post_id , $product );
} else {
$this -> bulk_edit_save ( $post_id , $product );
}
return $post_id ;
}
/**
2016-11-16 20:48:42 +00:00
* Quick edit .
2014-11-30 06:52:32 +00:00
*
2016-11-16 20:48:42 +00:00
* @ param integer $post_id
2015-01-23 14:37:20 +00:00
* @ param WC_Product $product
2014-06-04 10:16:19 +00:00
*/
private function quick_edit_save ( $post_id , $product ) {
2016-11-16 20:48:42 +00:00
$data_store = $product -> get_data_store ();
$old_regular_price = $product -> get_regular_price ();
$old_sale_price = $product -> get_sale_price ();
2014-06-04 10:16:19 +00:00
// Save fields
if ( isset ( $_REQUEST [ '_sku' ] ) ) {
2016-11-16 20:48:42 +00:00
$sku = $product -> get_sku ();
2016-06-07 10:22:36 +00:00
$new_sku = ( string ) wc_clean ( $_REQUEST [ '_sku' ] );
2014-06-04 10:16:19 +00:00
if ( $new_sku !== $sku ) {
if ( ! empty ( $new_sku ) ) {
2014-06-27 19:03:25 +00:00
$unique_sku = wc_product_has_unique_sku ( $post_id , $new_sku );
2014-06-27 18:58:29 +00:00
if ( $unique_sku ) {
2016-11-16 20:48:42 +00:00
$product -> set_sku ( $new_sku );
2014-06-04 10:16:19 +00:00
}
} else {
2016-11-16 20:48:42 +00:00
$product -> set_sku ( '' );
2014-06-04 10:16:19 +00:00
}
}
}
if ( isset ( $_REQUEST [ '_weight' ] ) ) {
2016-11-16 20:48:42 +00:00
$product -> set_weight ( wc_clean ( $_REQUEST [ '_weight' ] ) );
2014-06-04 10:16:19 +00:00
}
if ( isset ( $_REQUEST [ '_length' ] ) ) {
2016-11-16 20:48:42 +00:00
$product -> set_length ( wc_clean ( $_REQUEST [ '_length' ] ) );
2014-06-04 10:16:19 +00:00
}
if ( isset ( $_REQUEST [ '_width' ] ) ) {
2016-11-16 20:48:42 +00:00
$product -> set_width ( wc_clean ( $_REQUEST [ '_width' ] ) );
2014-06-04 10:16:19 +00:00
}
if ( isset ( $_REQUEST [ '_height' ] ) ) {
2016-11-16 20:48:42 +00:00
$product -> set_height ( wc_clean ( $_REQUEST [ '_height' ] ) );
2014-06-04 10:16:19 +00:00
}
2014-11-04 19:49:15 +00:00
if ( ! empty ( $_REQUEST [ '_shipping_class' ] ) ) {
2017-02-23 15:48:53 +00:00
if ( '_no_shipping_class' === $_REQUEST [ '_shipping_class' ] ) {
$product -> set_shipping_class_id ( 0 );
} else {
$shipping_class_id = $data_store -> get_shipping_class_id_by_slug ( wc_clean ( $_REQUEST [ '_shipping_class' ] ) );
2016-11-16 20:48:42 +00:00
$product -> set_shipping_class_id ( $shipping_class_id );
}
2014-11-04 19:49:15 +00:00
}
2014-06-04 10:16:19 +00:00
if ( isset ( $_REQUEST [ '_visibility' ] ) ) {
2016-11-16 20:48:42 +00:00
$product -> set_catalog_visibility ( wc_clean ( $_REQUEST [ '_visibility' ] ) );
2014-06-04 10:16:19 +00:00
}
if ( isset ( $_REQUEST [ '_featured' ] ) ) {
2016-11-16 20:48:42 +00:00
$product -> set_featured ( true );
2014-09-19 17:49:26 +00:00
} else {
2016-11-16 20:48:42 +00:00
$product -> set_featured ( false );
2014-06-04 10:16:19 +00:00
}
if ( isset ( $_REQUEST [ '_tax_status' ] ) ) {
2016-11-16 20:48:42 +00:00
$product -> set_tax_status ( wc_clean ( $_REQUEST [ '_tax_status' ] ) );
2014-06-04 10:16:19 +00:00
}
if ( isset ( $_REQUEST [ '_tax_class' ] ) ) {
2016-11-16 20:48:42 +00:00
$product -> set_tax_class ( wc_clean ( $_REQUEST [ '_tax_class' ] ) );
2014-06-04 10:16:19 +00:00
}
2016-09-02 01:51:31 +00:00
if ( $product -> is_type ( 'simple' ) || $product -> is_type ( 'external' ) ) {
2014-06-04 10:16:19 +00:00
if ( isset ( $_REQUEST [ '_regular_price' ] ) ) {
2016-09-09 00:14:28 +00:00
$new_regular_price = ( '' === $_REQUEST [ '_regular_price' ] ) ? '' : wc_format_decimal ( $_REQUEST [ '_regular_price' ] );
2016-11-16 20:48:42 +00:00
$product -> set_regular_price ( $new_regular_price );
2014-06-04 10:16:19 +00:00
} else {
$new_regular_price = null ;
}
if ( isset ( $_REQUEST [ '_sale_price' ] ) ) {
2016-09-09 00:14:28 +00:00
$new_sale_price = ( '' === $_REQUEST [ '_sale_price' ] ) ? '' : wc_format_decimal ( $_REQUEST [ '_sale_price' ] );
2016-11-16 20:48:42 +00:00
$product -> set_sale_price ( $new_sale_price );
2014-06-04 10:16:19 +00:00
} 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 ) {
2016-11-16 20:48:42 +00:00
$product -> set_date_on_sale_to ( '' );
$product -> set_date_on_sale_from ( '' );
2014-06-04 10:16:19 +00:00
}
}
2016-10-12 11:51:40 +00:00
// Handle Stock Data
2016-11-16 20:48:42 +00:00
$manage_stock = ! empty ( $_REQUEST [ '_manage_stock' ] ) && 'grouped' !== $product -> get_type () ? 'yes' : 'no' ;
2016-10-12 11:51:40 +00:00
$backorders = ! empty ( $_REQUEST [ '_backorders' ] ) ? wc_clean ( $_REQUEST [ '_backorders' ] ) : 'no' ;
$stock_status = ! empty ( $_REQUEST [ '_stock_status' ] ) ? wc_clean ( $_REQUEST [ '_stock_status' ] ) : 'instock' ;
$stock_amount = 'yes' === $manage_stock ? wc_stock_amount ( $_REQUEST [ '_stock' ] ) : '' ;
2014-11-12 15:15:05 +00:00
2017-08-07 14:16:38 +00:00
$product -> set_manage_stock ( $manage_stock );
$product -> set_backorders ( $backorders );
2016-10-12 11:51:40 +00:00
if ( 'yes' === get_option ( 'woocommerce_manage_stock' ) ) {
2017-08-07 14:16:38 +00:00
$product -> set_stock_quantity ( $stock_amount );
}
2016-10-12 11:51:40 +00:00
2017-08-07 14:16:38 +00:00
// Apply product type constraints to stock status.
if ( $product -> is_type ( 'external' ) ) {
// External products are always in stock.
$product -> set_stock_status ( 'instock' );
} elseif ( $product -> is_type ( 'variable' ) && ! $product -> get_manage_stock () ) {
// Stock status is determined by children.
foreach ( $product -> get_children () as $child_id ) {
$child = wc_get_product ( $child_id );
if ( ! $product -> get_manage_stock () ) {
$child -> set_stock_status ( $stock_status );
$child -> save ();
2014-11-12 15:15:05 +00:00
}
}
2017-08-07 14:16:38 +00:00
$product = WC_Product_Variable :: sync ( $product , false );
2016-10-12 11:51:40 +00:00
} else {
2017-08-07 14:16:38 +00:00
$product -> set_stock_status ( $stock_status );
2014-06-04 10:16:19 +00:00
}
2017-08-07 14:16:38 +00:00
$product -> save ();
2014-06-04 10:16:19 +00:00
do_action ( 'woocommerce_product_quick_edit_save' , $product );
}
/**
2015-11-03 12:28:01 +00:00
* Bulk edit .
2016-11-16 20:48:42 +00:00
*
2014-09-07 23:37:55 +00:00
* @ param integer $post_id
2015-01-23 14:37:20 +00:00
* @ param WC_Product $product
2014-06-04 10:16:19 +00:00
*/
public function bulk_edit_save ( $post_id , $product ) {
2016-12-14 11:26:21 +00:00
$data_store = $product -> get_data_store ();
2016-11-16 20:48:42 +00:00
$old_regular_price = $product -> get_regular_price ();
$old_sale_price = $product -> get_sale_price ();
2014-06-04 10:16:19 +00:00
// Save fields
if ( ! empty ( $_REQUEST [ 'change_weight' ] ) && isset ( $_REQUEST [ '_weight' ] ) ) {
2016-11-16 20:48:42 +00:00
$product -> set_weight ( wc_clean ( stripslashes ( $_REQUEST [ '_weight' ] ) ) );
2014-06-04 10:16:19 +00:00
}
if ( ! empty ( $_REQUEST [ 'change_dimensions' ] ) ) {
if ( isset ( $_REQUEST [ '_length' ] ) ) {
2016-11-16 20:48:42 +00:00
$product -> set_length ( wc_clean ( stripslashes ( $_REQUEST [ '_length' ] ) ) );
2014-06-04 10:16:19 +00:00
}
if ( isset ( $_REQUEST [ '_width' ] ) ) {
2016-11-16 20:48:42 +00:00
$product -> set_width ( wc_clean ( stripslashes ( $_REQUEST [ '_width' ] ) ) );
2014-06-04 10:16:19 +00:00
}
if ( isset ( $_REQUEST [ '_height' ] ) ) {
2016-11-16 20:48:42 +00:00
$product -> set_height ( wc_clean ( stripslashes ( $_REQUEST [ '_height' ] ) ) );
2014-06-04 10:16:19 +00:00
}
}
if ( ! empty ( $_REQUEST [ '_tax_status' ] ) ) {
2016-11-16 20:48:42 +00:00
$product -> set_tax_status ( wc_clean ( $_REQUEST [ '_tax_status' ] ) );
2014-06-04 10:16:19 +00:00
}
if ( ! empty ( $_REQUEST [ '_tax_class' ] ) ) {
$tax_class = wc_clean ( $_REQUEST [ '_tax_class' ] );
if ( 'standard' == $tax_class ) {
$tax_class = '' ;
}
2016-11-16 20:48:42 +00:00
$product -> set_tax_class ( $tax_class );
2014-06-04 10:16:19 +00:00
}
2014-11-04 19:49:15 +00:00
if ( ! empty ( $_REQUEST [ '_shipping_class' ] ) ) {
2017-02-23 15:48:53 +00:00
if ( '_no_shipping_class' === $_REQUEST [ '_shipping_class' ] ) {
$product -> set_shipping_class_id ( 0 );
} else {
$shipping_class_id = $data_store -> get_shipping_class_id_by_slug ( wc_clean ( $_REQUEST [ '_shipping_class' ] ) );
2016-11-16 20:48:42 +00:00
$product -> set_shipping_class_id ( $shipping_class_id );
}
2014-11-04 19:49:15 +00:00
}
2014-06-04 10:16:19 +00:00
if ( ! empty ( $_REQUEST [ '_visibility' ] ) ) {
2016-11-16 20:48:42 +00:00
$product -> set_catalog_visibility ( wc_clean ( $_REQUEST [ '_visibility' ] ) );
2014-06-04 10:16:19 +00:00
}
if ( ! empty ( $_REQUEST [ '_featured' ] ) ) {
2016-11-16 20:48:42 +00:00
$product -> set_featured ( stripslashes ( $_REQUEST [ '_featured' ] ) );
2014-06-04 10:16:19 +00:00
}
// Sold Individually
if ( ! empty ( $_REQUEST [ '_sold_individually' ] ) ) {
2016-09-09 00:14:28 +00:00
if ( 'yes' === $_REQUEST [ '_sold_individually' ] ) {
2016-11-16 20:48:42 +00:00
$product -> set_sold_individually ( 'yes' );
2016-09-02 03:15:49 +00:00
} else {
2016-11-16 20:48:42 +00:00
$product -> set_sold_individually ( '' );
2014-06-04 10:16:19 +00:00
}
}
// Handle price - remove dates and set to lowest
2015-11-23 15:47:41 +00:00
$change_price_product_types = apply_filters ( 'woocommerce_bulk_edit_save_price_product_types' , array ( 'simple' , 'external' ) );
$can_product_type_change_price = false ;
foreach ( $change_price_product_types as $product_type ) {
if ( $product -> is_type ( $product_type ) ) {
$can_product_type_change_price = true ;
break ;
}
}
if ( $can_product_type_change_price ) {
2014-06-04 10:16:19 +00:00
$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 ;
2015-01-23 11:50:32 +00:00
$new_price = $old_regular_price + ( round ( $old_regular_price * $percent , wc_get_price_decimals () ) );
2014-06-04 10:16:19 +00:00
} else {
$new_price = $old_regular_price + $regular_price ;
}
break ;
case 3 :
if ( strstr ( $regular_price , '%' ) ) {
$percent = str_replace ( '%' , '' , $regular_price ) / 100 ;
2016-09-02 01:12:22 +00:00
$new_price = max ( 0 , $old_regular_price - ( round ( $old_regular_price * $percent , wc_get_price_decimals () ) ) );
2014-06-04 10:16:19 +00:00
} else {
2014-09-19 11:18:04 +00:00
$new_price = max ( 0 , $old_regular_price - $regular_price );
2014-06-04 10:16:19 +00:00
}
break ;
default :
break ;
}
if ( isset ( $new_price ) && $new_price != $old_regular_price ) {
$price_changed = true ;
2015-01-23 11:50:32 +00:00
$new_price = round ( $new_price , wc_get_price_decimals () );
2016-11-16 20:48:42 +00:00
$product -> set_regular_price ( $new_price );
2014-06-04 10:16:19 +00:00
}
}
if ( ! empty ( $_REQUEST [ 'change_sale_price' ] ) ) {
$change_sale_price = absint ( $_REQUEST [ 'change_sale_price' ] );
2014-09-19 11:18:04 +00:00
$sale_price = esc_attr ( stripslashes ( $_REQUEST [ '_sale_price' ] ) );
2014-06-04 10:16:19 +00:00
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 ;
2014-09-19 11:18:04 +00:00
$new_price = max ( 0 , $old_sale_price - ( $old_sale_price * $percent ) );
2014-06-04 10:16:19 +00:00
} else {
2014-09-19 11:18:04 +00:00
$new_price = max ( 0 , $old_sale_price - $sale_price );
2014-06-04 10:16:19 +00:00
}
break ;
case 4 :
if ( strstr ( $sale_price , '%' ) ) {
$percent = str_replace ( '%' , '' , $sale_price ) / 100 ;
2014-09-19 11:18:04 +00:00
$new_price = max ( 0 , $product -> regular_price - ( $product -> regular_price * $percent ) );
2014-06-04 10:16:19 +00:00
} else {
2014-09-19 11:18:04 +00:00
$new_price = max ( 0 , $product -> regular_price - $sale_price );
2014-06-04 10:16:19 +00:00
}
break ;
default :
break ;
}
2015-10-27 13:27:31 +00:00
if ( isset ( $new_price ) && $new_price != $old_sale_price ) {
2014-06-04 10:16:19 +00:00
$price_changed = true ;
2015-11-06 16:42:51 +00:00
$new_price = ! empty ( $new_price ) || '0' === $new_price ? round ( $new_price , wc_get_price_decimals () ) : '' ;
2016-11-16 20:48:42 +00:00
$product -> set_sale_price ( $new_price );
2014-06-04 10:16:19 +00:00
}
}
if ( $price_changed ) {
2016-11-16 20:48:42 +00:00
$product -> set_date_on_sale_to ( '' );
$product -> set_date_on_sale_from ( '' );
2014-06-04 10:16:19 +00:00
2016-11-16 20:48:42 +00:00
if ( $product -> get_regular_price () < $product -> get_sale_price () ) {
$product -> set_sale_price ( '' );
2014-06-04 10:16:19 +00:00
}
}
}
2016-10-12 11:51:40 +00:00
// Handle Stock Data
2016-11-16 20:48:42 +00:00
$was_managing_stock = $product -> get_manage_stock () ? 'yes' : 'no' ;
$stock_status = $product -> get_stock_status ();
$backorders = $product -> get_backorders ();
2017-08-07 14:16:38 +00:00
$backorders = ! empty ( $_REQUEST [ '_backorders' ] ) ? wc_clean ( $_REQUEST [ '_backorders' ] ) : $backorders ;
$stock_status = ! empty ( $_REQUEST [ '_stock_status' ] ) ? wc_clean ( $_REQUEST [ '_stock_status' ] ) : $stock_status ;
2014-06-04 10:16:19 +00:00
2016-10-12 11:51:40 +00:00
if ( ! empty ( $_REQUEST [ '_manage_stock' ] ) ) {
2017-07-31 21:16:08 +00:00
$manage_stock = 'yes' === wc_clean ( $_REQUEST [ '_manage_stock' ] ) && 'grouped' !== $product -> get_type () ? 'yes' : 'no' ;
2016-10-12 11:51:40 +00:00
} else {
$manage_stock = $was_managing_stock ;
}
2014-06-04 10:16:19 +00:00
2017-01-16 18:57:14 +00:00
$stock_amount = 'yes' === $manage_stock && ! empty ( $_REQUEST [ 'change_stock' ] ) ? wc_stock_amount ( $_REQUEST [ '_stock' ] ) : $product -> get_stock_quantity ();
2016-10-12 11:51:40 +00:00
2017-08-07 14:16:38 +00:00
$product -> set_manage_stock ( $manage_stock );
$product -> set_backorders ( $backorders );
2016-10-12 11:51:40 +00:00
if ( 'yes' === get_option ( 'woocommerce_manage_stock' ) ) {
2017-08-07 14:16:38 +00:00
$product -> set_stock_quantity ( $stock_amount );
}
2016-10-12 11:51:40 +00:00
2017-08-07 14:16:38 +00:00
// Apply product type constraints to stock status.
if ( $product -> is_type ( 'external' ) ) {
// External products are always in stock.
$product -> set_stock_status ( 'instock' );
} elseif ( $product -> is_type ( 'variable' ) && ! $product -> get_manage_stock () ) {
// Stock status is determined by children.
foreach ( $product -> get_children () as $child_id ) {
$child = wc_get_product ( $child_id );
if ( ! $product -> get_manage_stock () ) {
$child -> set_stock_status ( $stock_status );
$child -> save ();
2014-06-04 10:16:19 +00:00
}
}
2017-08-07 14:16:38 +00:00
$product = WC_Product_Variable :: sync ( $product , false );
2016-10-12 11:51:40 +00:00
} else {
2017-08-07 14:16:38 +00:00
$product -> set_stock_status ( $stock_status );
2014-06-04 10:16:19 +00:00
}
2017-08-07 14:16:38 +00:00
$product -> save ();
2014-06-04 10:16:19 +00:00
do_action ( 'woocommerce_product_bulk_edit_save' , $product );
}
2016-11-17 20:57:48 +00:00
/**
2016-11-18 11:13:37 +00:00
* Manipulate shop order bulk actions .
2016-11-17 20:57:48 +00:00
*
* @ param array $actions List of actions .
* @ return array
*/
public function shop_order_bulk_actions ( $actions ) {
if ( isset ( $actions [ 'edit' ] ) ) {
unset ( $actions [ 'edit' ] );
}
2014-11-19 12:26:27 +00:00
2016-11-17 20:57:48 +00:00
$actions [ 'mark_processing' ] = __ ( 'Mark processing' , 'woocommerce' );
$actions [ 'mark_on-hold' ] = __ ( 'Mark on-hold' , 'woocommerce' );
$actions [ 'mark_completed' ] = __ ( 'Mark complete' , 'woocommerce' );
return $actions ;
}
/**
* Handle shop order bulk actions .
*
2017-03-15 16:36:53 +00:00
* @ since 3.0 . 0
2016-11-17 20:57:48 +00:00
* @ param string $redirect_to URL to redirect to .
* @ param string $action Action name .
* @ param array $ids List of ids .
* @ return string
*/
public function handle_shop_order_bulk_actions ( $redirect_to , $action , $ids ) {
// Bail out if this is not a status-changing action.
if ( false === strpos ( $action , 'mark_' ) ) {
return $redirect_to ;
}
$order_statuses = wc_get_order_statuses ();
$new_status = substr ( $action , 5 ); // Get the status name from action.
$report_action = 'marked_' . $new_status ;
2014-11-19 12:26:27 +00:00
// Sanity check: bail out if this is actually not a status, or is
2016-11-17 20:57:48 +00:00
// not a registered status.
2014-11-19 12:26:27 +00:00
if ( ! isset ( $order_statuses [ 'wc-' . $new_status ] ) ) {
2016-11-17 20:57:48 +00:00
return $redirect_to ;
2014-06-04 10:16:19 +00:00
}
$changed = 0 ;
2016-11-17 20:57:48 +00:00
$ids = array_map ( 'absint' , $ids );
2014-06-04 10:16:19 +00:00
2016-11-17 20:57:48 +00:00
foreach ( $ids as $id ) {
$order = wc_get_order ( $id );
2015-08-18 15:33:36 +00:00
$order -> update_status ( $new_status , __ ( 'Order status changed by bulk edit:' , 'woocommerce' ), true );
2016-11-17 20:57:48 +00:00
do_action ( 'woocommerce_order_edit_status' , $id , $new_status );
2014-06-04 10:16:19 +00:00
$changed ++ ;
}
2016-11-17 20:57:48 +00:00
$redirect_to = add_query_arg ( array (
'post_type' => 'shop_order' ,
$report_action => true ,
'changed' => $changed ,
2016-11-18 11:13:37 +00:00
'ids' => join ( ',' , $ids ),
2016-11-17 20:57:48 +00:00
), $redirect_to );
2015-04-23 12:50:40 +00:00
2016-11-17 20:57:48 +00:00
return esc_url_raw ( $redirect_to );
2014-06-04 10:16:19 +00:00
}
/**
2015-11-03 12:28:01 +00:00
* Show confirmation message that order status changed for number of orders .
2013-07-24 16:01:36 +00:00
*/
2014-06-04 10:16:19 +00:00
public function bulk_admin_notices () {
global $post_type , $pagenow ;
2013-08-06 15:56:15 +00:00
2014-11-19 12:26:27 +00:00
// Bail out if not on shop order list page
if ( 'edit.php' !== $pagenow || 'shop_order' !== $post_type ) {
return ;
}
$order_statuses = wc_get_order_statuses ();
// Check if any status changes happened
foreach ( $order_statuses as $slug => $name ) {
2014-06-04 10:16:19 +00:00
2014-11-19 12:26:27 +00:00
if ( isset ( $_REQUEST [ 'marked_' . str_replace ( 'wc-' , '' , $slug ) ] ) ) {
$number = isset ( $_REQUEST [ 'changed' ] ) ? absint ( $_REQUEST [ 'changed' ] ) : 0 ;
2016-10-29 10:16:03 +00:00
/* translators: %s: orders count */
2014-06-04 10:16:19 +00:00
$message = sprintf ( _n ( 'Order status changed.' , '%s order statuses changed.' , $number , 'woocommerce' ), number_format_i18n ( $number ) );
echo '<div class="updated"><p>' . $message . '</p></div>' ;
2014-11-19 12:26:27 +00:00
break ;
2014-06-04 10:16:19 +00:00
}
}
2013-07-24 16:01:36 +00:00
}
/**
2014-06-04 10:16:19 +00:00
* Search custom fields as well as content .
* @ param WP_Query $wp
2013-07-24 16:01:36 +00:00
*/
2014-06-04 10:16:19 +00:00
public function shop_order_search_custom_fields ( $wp ) {
2016-06-13 13:42:10 +00:00
global $pagenow ;
2013-07-24 18:55:02 +00:00
2016-09-09 00:14:28 +00:00
if ( 'edit.php' != $pagenow || empty ( $wp -> query_vars [ 's' ] ) || 'shop_order' !== $wp -> query_vars [ 'post_type' ] ) {
2014-06-04 10:16:19 +00:00
return ;
}
2016-06-13 13:42:10 +00:00
$post_ids = wc_order_search ( $_GET [ 's' ] );
2014-06-04 10:16:19 +00:00
2016-06-13 18:26:14 +00:00
if ( ! empty ( $post_ids ) ) {
2016-06-13 13:42:10 +00:00
// Remove "s" - we don't want to search order name.
2016-03-08 12:58:29 +00:00
unset ( $wp -> query_vars [ 's' ] );
2014-06-04 10:16:19 +00:00
2016-06-13 13:42:10 +00:00
// so we know we're doing this.
2016-03-08 12:58:29 +00:00
$wp -> query_vars [ 'shop_order_search' ] = true ;
2014-06-04 10:16:19 +00:00
2016-06-13 13:42:10 +00:00
// Search by found posts.
2016-03-24 11:21:30 +00:00
$wp -> query_vars [ 'post__in' ] = array_merge ( $post_ids , array ( 0 ) );
2016-03-08 12:58:29 +00:00
}
2014-06-04 10:16:19 +00:00
}
/**
* Change the label when searching orders .
*
* @ param mixed $query
* @ return string
*/
public function shop_order_search_label ( $query ) {
global $pagenow , $typenow ;
if ( 'edit.php' != $pagenow ) {
return $query ;
}
2016-09-09 00:14:28 +00:00
if ( 'shop_order' !== $typenow ) {
2014-06-04 10:16:19 +00:00
return $query ;
}
if ( ! get_query_var ( 'shop_order_search' ) ) {
return $query ;
}
return wp_unslash ( $_GET [ 's' ] );
}
/**
* Query vars for custom searches .
*
* @ 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 ;
}
/**
2015-11-03 12:28:01 +00:00
* Filters for post types .
2014-06-04 10:16:19 +00:00
*/
public function restrict_manage_posts () {
2015-10-01 09:43:41 +00:00
global $typenow ;
2014-06-04 10:16:19 +00:00
2014-11-26 21:27:49 +00:00
if ( in_array ( $typenow , wc_get_order_types ( 'order-meta-boxes' ) ) ) {
$this -> shop_order_filters ();
} elseif ( 'product' == $typenow ) {
$this -> product_filters ();
2016-08-27 04:23:02 +00:00
} elseif ( 'shop_coupon' == $typenow ) {
2014-11-26 21:27:49 +00:00
$this -> shop_coupon_filters ();
2014-06-04 10:16:19 +00:00
}
}
/**
2015-11-03 12:28:01 +00:00
* Show a category filter box .
2014-06-04 10:16:19 +00:00
*/
public function product_filters () {
global $wp_query ;
// Category Filtering
2017-07-13 16:04:40 +00:00
$current_category_slug = isset ( $_GET [ 'product_cat' ] ) ? wc_clean ( $_GET [ 'product_cat' ] ) : false ;
$current_category = $current_category_slug ? get_term_by ( 'slug' , $current_category_slug , 'product_cat' ) : false ;
?>
< select class = " wc-category-search " name = " product_cat " data - placeholder = " <?php esc_attr_e( 'Filter by category', 'woocommerce' ); ?> " data - allow_clear = " true " >
< ? php if ( $current_category_slug && $current_category ) : ?>
< option value = " <?php echo esc_attr( $current_category_slug ); ?> " selected = " selected " >< ? php echo esc_html ( $current_category -> name ); ?> <option>
< ? php endif ; ?>
</ select >
< ? php
2014-06-04 10:16:19 +00:00
// Type filtering
$terms = get_terms ( 'product_type' );
$output = '<select name="product_type" id="dropdown_product_type">' ;
2017-05-16 14:05:11 +00:00
$output .= '<option value="">' . __ ( 'Filter by product type' , 'woocommerce' ) . '</option>' ;
2014-06-04 10:16:19 +00:00
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 ;
}
2015-07-25 01:36:51 +00:00
$output .= '</option>' ;
2014-06-04 10:16:19 +00:00
if ( 'simple' == $term -> name ) {
$output .= '<option value="downloadable" ' ;
if ( isset ( $wp_query -> query [ 'product_type' ] ) ) {
$output .= selected ( 'downloadable' , $wp_query -> query [ 'product_type' ], false );
}
2016-10-25 23:34:50 +00:00
$output .= '> ' . ( is_rtl () ? '←' : '→' ) . ' ' . __ ( 'Downloadable' , 'woocommerce' ) . '</option>' ;
2014-06-04 10:16:19 +00:00
$output .= '<option value="virtual" ' ;
if ( isset ( $wp_query -> query [ 'product_type' ] ) ) {
$output .= selected ( 'virtual' , $wp_query -> query [ 'product_type' ], false );
}
2016-10-25 23:34:50 +00:00
$output .= '> ' . ( is_rtl () ? '←' : '→' ) . ' ' . __ ( 'Virtual' , 'woocommerce' ) . '</option>' ;
2014-06-04 10:16:19 +00:00
}
}
$output .= '</select>' ;
echo apply_filters ( 'woocommerce_product_filters' , $output );
}
/**
* Show custom filters to filter coupons by type .
*/
public function shop_coupon_filters () {
?>
2015-01-12 13:04:19 +00:00
< select name = " coupon_type " id = " dropdown_shop_coupon_type " >
2014-06-04 10:16:19 +00:00
< option value = " " >< ? php _e ( 'Show all types' , 'woocommerce' ); ?> </option>
< ? php
$types = wc_get_coupon_types ();
foreach ( $types as $name => $type ) {
echo '<option value="' . esc_attr ( $name ) . '"' ;
2016-09-01 20:50:14 +00:00
if ( isset ( $_GET [ 'coupon_type' ] ) ) {
2014-06-04 10:16:19 +00:00
selected ( $name , $_GET [ 'coupon_type' ] );
2016-09-01 20:50:14 +00:00
}
2014-06-04 10:16:19 +00:00
2016-09-01 20:50:14 +00:00
echo '>' . esc_html ( $type ) . '</option>' ;
2014-06-04 10:16:19 +00:00
}
?>
2015-01-12 13:04:19 +00:00
</ select >
2014-06-04 10:16:19 +00:00
< ? php
}
/**
* Show custom filters to filter orders by status / customer .
*/
public function shop_order_filters () {
2015-01-12 13:04:19 +00:00
$user_string = '' ;
$user_id = '' ;
if ( ! empty ( $_GET [ '_customer_user' ] ) ) {
$user_id = absint ( $_GET [ '_customer_user' ] );
$user = get_user_by ( 'id' , $user_id );
2016-10-29 10:16:03 +00:00
/* translators: 1: user display name 2: user ID 3: user email */
2016-10-13 16:34:48 +00:00
$user_string = sprintf (
esc_html__ ( '%1$s (#%2$s – %3$s)' , 'woocommerce' ),
$user -> display_name ,
absint ( $user -> ID ),
$user -> user_email
);
2015-01-12 13:04:19 +00:00
}
2014-06-04 10:16:19 +00:00
?>
2016-12-21 14:18:33 +00:00
< select class = " wc-customer-search " name = " _customer_user " data - placeholder = " <?php esc_attr_e( 'Search for a customer…', 'woocommerce' ); ?> " data - allow_clear = " true " >
< option value = " <?php echo esc_attr( $user_id ); ?> " selected = " selected " >< ? php echo htmlspecialchars ( $user_string ); ?> <option>
</ select >
2014-06-04 10:16:19 +00:00
< ? php
}
/**
2015-11-03 12:28:01 +00:00
* Filters and sorting handler .
2014-11-30 06:52:32 +00:00
*
2014-06-04 10:16:19 +00:00
* @ param array $vars
* @ return array
*/
public function request_query ( $vars ) {
2015-03-31 12:09:43 +00:00
global $typenow , $wp_query , $wp_post_statuses ;
2014-06-04 10:16:19 +00:00
if ( 'product' === $typenow ) {
// Sorting
if ( isset ( $vars [ 'orderby' ] ) ) {
if ( 'price' == $vars [ 'orderby' ] ) {
$vars = array_merge ( $vars , array (
2014-11-30 06:52:32 +00:00
'meta_key' => '_price' ,
2016-08-27 01:46:45 +00:00
'orderby' => 'meta_value_num' ,
2014-06-04 10:16:19 +00:00
) );
}
if ( 'sku' == $vars [ 'orderby' ] ) {
$vars = array_merge ( $vars , array (
2014-11-30 06:52:32 +00:00
'meta_key' => '_sku' ,
2016-08-27 01:46:45 +00:00
'orderby' => 'meta_value' ,
2014-06-04 10:16:19 +00:00
) );
}
}
} elseif ( 'shop_coupon' === $typenow ) {
if ( ! empty ( $_GET [ 'coupon_type' ] ) ) {
2014-11-30 06:52:32 +00:00
$vars [ 'meta_key' ] = 'discount_type' ;
2014-06-04 10:16:19 +00:00
$vars [ 'meta_value' ] = wc_clean ( $_GET [ 'coupon_type' ] );
}
2014-11-26 21:30:33 +00:00
} elseif ( in_array ( $typenow , wc_get_order_types ( 'order-meta-boxes' ) ) ) {
2014-07-11 11:43:42 +00:00
2014-06-04 10:16:19 +00:00
// Filter the orders by the posted customer.
if ( isset ( $_GET [ '_customer_user' ] ) && $_GET [ '_customer_user' ] > 0 ) {
2015-08-13 03:33:56 +00:00
$vars [ 'meta_query' ] = array (
array (
'key' => '_customer_user' ,
'value' => ( int ) $_GET [ '_customer_user' ],
2016-08-27 01:46:45 +00:00
'compare' => '=' ,
2016-08-27 02:08:49 +00:00
),
2015-08-13 03:33:56 +00:00
);
2014-06-04 10:16:19 +00:00
}
// Sorting
if ( isset ( $vars [ 'orderby' ] ) ) {
if ( 'order_total' == $vars [ 'orderby' ] ) {
$vars = array_merge ( $vars , array (
2014-11-30 06:52:32 +00:00
'meta_key' => '_order_total' ,
2016-08-27 01:46:45 +00:00
'orderby' => 'meta_value_num' ,
2014-06-04 10:16:19 +00:00
) );
}
}
2014-10-03 13:35:45 +00:00
// Status
if ( ! isset ( $vars [ 'post_status' ] ) ) {
2015-03-31 12:09:43 +00:00
$post_statuses = wc_get_order_statuses ();
foreach ( $post_statuses as $status => $value ) {
if ( isset ( $wp_post_statuses [ $status ] ) && false === $wp_post_statuses [ $status ] -> show_in_admin_all_list ) {
unset ( $post_statuses [ $status ] );
}
}
$vars [ 'post_status' ] = array_keys ( $post_statuses );
2014-10-03 13:35:45 +00:00
}
2014-06-04 10:16:19 +00:00
}
return $vars ;
}
/**
2015-11-03 12:28:01 +00:00
* Filter the products in admin based on options .
2014-06-04 10:16:19 +00:00
*
* @ param mixed $query
*/
public function product_filters_query ( $query ) {
global $typenow , $wp_query ;
if ( 'product' == $typenow ) {
if ( isset ( $query -> query_vars [ 'product_type' ] ) ) {
// Subtypes
if ( 'downloadable' == $query -> query_vars [ 'product_type' ] ) {
$query -> query_vars [ 'product_type' ] = '' ;
2015-01-19 13:39:59 +00:00
$query -> is_tax = false ;
2014-06-04 10:16:19 +00:00
$query -> query_vars [ 'meta_value' ] = 'yes' ;
$query -> query_vars [ 'meta_key' ] = '_downloadable' ;
} elseif ( 'virtual' == $query -> query_vars [ 'product_type' ] ) {
$query -> query_vars [ 'product_type' ] = '' ;
2015-01-19 13:39:59 +00:00
$query -> is_tax = false ;
2014-06-04 10:16:19 +00:00
$query -> query_vars [ 'meta_value' ] = 'yes' ;
$query -> query_vars [ 'meta_key' ] = '_virtual' ;
}
}
2016-04-18 08:44:14 +00:00
// Shipping classes
if ( isset ( $_GET [ 'product_shipping_class' ] ) && '0' === $_GET [ 'product_shipping_class' ] ) {
$query -> query_vars [ 'tax_query' ][] = array (
'taxonomy' => 'product_shipping_class' ,
'field' => 'id' ,
'terms' => get_terms ( 'product_shipping_class' , array ( 'fields' => 'ids' ) ),
2016-08-27 01:46:45 +00:00
'operator' => 'NOT IN' ,
2016-04-18 08:44:14 +00:00
);
}
2014-06-04 10:16:19 +00:00
}
}
/**
* Search by SKU or ID for products .
2014-11-30 06:52:32 +00:00
*
2014-06-04 10:16:19 +00:00
* @ param string $where
* @ return string
*/
public function product_search ( $where ) {
global $pagenow , $wpdb , $wp ;
if ( 'edit.php' != $pagenow || ! is_search () || ! isset ( $wp -> query_vars [ 's' ] ) || 'product' != $wp -> query_vars [ 'post_type' ] ) {
return $where ;
}
$search_ids = array ();
$terms = explode ( ',' , $wp -> query_vars [ 's' ] );
foreach ( $terms as $term ) {
if ( is_numeric ( $term ) ) {
$search_ids [] = $term ;
}
2015-10-02 08:52:23 +00:00
2014-06-04 10:16:19 +00:00
// Attempt to get a SKU
2015-10-02 08:52:23 +00:00
$sku_to_id = $wpdb -> get_results ( $wpdb -> prepare ( " SELECT ID, post_parent FROM { $wpdb -> posts } LEFT JOIN { $wpdb -> postmeta } ON { $wpdb -> posts } .ID = { $wpdb -> postmeta } .post_id WHERE meta_key='_sku' AND meta_value LIKE %s; " , '%' . $wpdb -> esc_like ( wc_clean ( $term ) ) . '%' ) );
$sku_to_id = array_merge ( wp_list_pluck ( $sku_to_id , 'ID' ), wp_list_pluck ( $sku_to_id , 'post_parent' ) );
2014-06-04 10:16:19 +00:00
2016-06-06 16:24:31 +00:00
if ( sizeof ( $sku_to_id ) > 0 ) {
2014-06-04 10:16:19 +00:00
$search_ids = array_merge ( $search_ids , $sku_to_id );
}
}
2015-10-02 08:52:23 +00:00
$search_ids = array_filter ( array_unique ( array_map ( 'absint' , $search_ids ) ) );
2014-06-04 10:16:19 +00:00
if ( sizeof ( $search_ids ) > 0 ) {
2015-06-17 13:56:51 +00:00
$where = str_replace ( 'AND (((' , " AND ( ( { $wpdb -> posts } .ID IN ( " . implode ( ',' , $search_ids ) . " )) OR (( " , $where );
2014-06-04 10:16:19 +00:00
}
return $where ;
2013-07-24 16:01:36 +00:00
}
2013-07-31 14:12:53 +00:00
/**
* Disable the auto - save functionality for Orders .
*/
2014-12-17 12:16:14 +00:00
public function disable_autosave () {
2014-10-07 05:16:59 +00:00
global $post ;
2013-07-31 14:12:53 +00:00
2014-10-07 05:16:59 +00:00
if ( $post && in_array ( get_post_type ( $post -> ID ), wc_get_order_types ( 'order-meta-boxes' ) ) ) {
wp_dequeue_script ( 'autosave' );
}
2013-07-31 14:12:53 +00:00
}
2013-07-24 16:01:36 +00:00
2017-01-04 15:18:02 +00:00
/**
* Output extra data on post forms .
* @ param WP_Post $post
*/
public function edit_form_top ( $post ) {
echo '<input type="hidden" id="original_post_title" name="original_post_title" value="' . esc_attr ( $post -> post_title ) . '" />' ;
}
2014-06-04 10:16:19 +00:00
/**
* Change title boxes in admin .
* @ param string $text
* @ param object $post
* @ return string
*/
public function enter_title_here ( $text , $post ) {
switch ( $post -> post_type ) {
case 'product' :
2014-11-19 23:36:47 +00:00
$text = __ ( 'Product name' , 'woocommerce' );
2014-06-04 10:16:19 +00:00
break ;
case 'shop_coupon' :
2014-11-19 23:36:47 +00:00
$text = __ ( 'Coupon code' , 'woocommerce' );
2014-06-04 10:16:19 +00:00
break ;
}
2014-11-19 23:36:47 +00:00
2014-06-04 10:16:19 +00:00
return $text ;
}
/**
2015-08-21 21:12:03 +00:00
* Print coupon description textarea field .
2014-06-04 10:16:19 +00:00
* @ param WP_Post $post
*/
2015-08-21 21:12:03 +00:00
public function edit_form_after_title ( $post ) {
2014-06-04 10:16:19 +00:00
if ( 'shop_coupon' === $post -> post_type ) {
?>
2015-10-05 13:30:02 +00:00
< textarea id = " woocommerce-coupon-description " name = " excerpt " cols = " 5 " rows = " 2 " placeholder = " <?php esc_attr_e( 'Description (optional)', 'woocommerce' ); ?> " >< ? php echo $post -> post_excerpt ; // This is already escaped in core ?></textarea>
2014-06-04 10:16:19 +00:00
< ? php
}
}
2015-08-21 21:07:05 +00:00
/**
* Hidden default Meta - Boxes .
* @ param array $hidden
* @ param object $screen
* @ return array
*/
public function hidden_meta_boxes ( $hidden , $screen ) {
if ( 'product' === $screen -> post_type && 'post' === $screen -> base ) {
$hidden = array_merge ( $hidden , array ( 'postcustom' ) );
}
return $hidden ;
}
2014-06-04 10:16:19 +00:00
/**
* Output product visibility options .
*/
public function product_data_visibility () {
2016-12-08 10:56:45 +00:00
global $post , $thepostid , $product_object ;
2014-06-04 10:16:19 +00:00
2016-12-08 10:56:45 +00:00
if ( 'product' !== $post -> post_type ) {
2014-06-04 10:16:19 +00:00
return ;
}
2016-12-08 10:56:45 +00:00
$thepostid = $post -> ID ;
$product_object = $thepostid ? wc_get_product ( $thepostid ) : new WC_Product ;
$current_visibility = $product_object -> get_catalog_visibility ();
$current_featured = wc_bool_to_string ( $product_object -> get_featured () );
$visibility_options = wc_get_product_visibility_options ();
2014-06-04 10:16:19 +00:00
?>
< div class = " misc-pub-section " id = " catalog-visibility " >
< ? php _e ( 'Catalog visibility:' , 'woocommerce' ); ?> <strong id="catalog-visibility-display"><?php
2016-09-02 01:33:57 +00:00
echo isset ( $visibility_options [ $current_visibility ] ) ? esc_html ( $visibility_options [ $current_visibility ] ) : esc_html ( $current_visibility );
2014-06-04 10:16:19 +00:00
2016-12-08 10:56:45 +00:00
if ( 'yes' === $current_featured ) {
2014-06-04 10:16:19 +00:00
echo ', ' . __ ( 'Featured' , 'woocommerce' );
}
?> </strong>
< a href = " #catalog-visibility " class = " edit-catalog-visibility hide-if-no-js " >< ? php _e ( 'Edit' , 'woocommerce' ); ?> </a>
< div id = " catalog-visibility-select " class = " hide-if-js " >
< input type = " hidden " name = " current_visibility " id = " current_visibility " value = " <?php echo esc_attr( $current_visibility ); ?> " />
< input type = " hidden " name = " current_featured " id = " current_featured " value = " <?php echo esc_attr( $current_featured ); ?> " />
< ? php
2017-06-14 11:07:20 +00:00
echo '<p>' . __ ( 'This setting determines which shop pages products will be listed on.' , 'woocommerce' ) . '</p>' ;
2014-06-04 10:16:19 +00:00
foreach ( $visibility_options as $name => $label ) {
echo '<input type="radio" name="_visibility" id="_visibility_' . esc_attr ( $name ) . '" value="' . esc_attr ( $name ) . '" ' . checked ( $current_visibility , $name , false ) . ' data-label="' . esc_attr ( $label ) . '" /> <label for="_visibility_' . esc_attr ( $name ) . '" class="selectit">' . esc_html ( $label ) . '</label><br />' ;
}
2017-06-14 11:07:20 +00:00
echo '<br /><input type="checkbox" name="_featured" id="_featured" ' . checked ( $current_featured , 'yes' , false ) . ' /> <label for="_featured">' . __ ( 'This is a featured product' , 'woocommerce' ) . '</label><br />' ;
2014-06-04 10:16:19 +00:00
?>
< p >
< a href = " #catalog-visibility " class = " save-post-visibility hide-if-no-js button " >< ? php _e ( 'OK' , 'woocommerce' ); ?> </a>
< a href = " #catalog-visibility " class = " cancel-post-visibility hide-if-no-js " >< ? php _e ( 'Cancel' , 'woocommerce' ); ?> </a>
</ p >
</ div >
</ div >
< ? php
}
/**
* Filter the directory for uploads .
*
* @ param array $pathdata
* @ return array
*/
public function upload_dir ( $pathdata ) {
2014-11-30 06:52:32 +00:00
2014-06-04 10:16:19 +00:00
// Change upload dir for downloadable files
if ( isset ( $_POST [ 'type' ] ) && 'downloadable_product' == $_POST [ 'type' ] ) {
2014-11-30 06:52:32 +00:00
2014-06-04 10:16:19 +00:00
if ( empty ( $pathdata [ 'subdir' ] ) ) {
$pathdata [ 'path' ] = $pathdata [ 'path' ] . '/woocommerce_uploads' ;
2016-09-01 20:50:14 +00:00
$pathdata [ 'url' ] = $pathdata [ 'url' ] . '/woocommerce_uploads' ;
2014-06-04 10:16:19 +00:00
$pathdata [ 'subdir' ] = '/woocommerce_uploads' ;
} else {
$new_subdir = '/woocommerce_uploads' . $pathdata [ 'subdir' ];
$pathdata [ 'path' ] = str_replace ( $pathdata [ 'subdir' ], $new_subdir , $pathdata [ 'path' ] );
$pathdata [ 'url' ] = str_replace ( $pathdata [ 'subdir' ], $new_subdir , $pathdata [ 'url' ] );
$pathdata [ 'subdir' ] = str_replace ( $pathdata [ 'subdir' ], $new_subdir , $pathdata [ 'subdir' ] );
}
}
return $pathdata ;
}
/**
* Run a filter when uploading a downloadable product .
*/
public function woocommerce_media_upload_downloadable_product () {
do_action ( 'media_upload_file' );
}
/**
2015-11-03 12:28:01 +00:00
* Grant downloadable file access to any newly added files on any existing .
* orders for this product that have previously been granted downloadable file access .
2014-06-04 10:16:19 +00:00
*
* @ param int $product_id product identifier
* @ param int $variation_id optional product variation identifier
* @ param array $downloadable_files newly set files
2016-11-18 19:29:37 +00:00
* @ deprecated and moved to post - data class .
2014-06-04 10:16:19 +00:00
*/
public function process_product_file_download_paths ( $product_id , $variation_id , $downloadable_files ) {
2016-11-18 19:29:37 +00:00
WC_Post_Data :: process_product_file_download_paths ( $product_id , $variation_id , $downloadable_files );
2014-06-12 07:59:45 +00:00
}
2015-07-20 17:15:51 +00:00
/**
2015-11-03 12:28:01 +00:00
* Disable DFW feature pointer .
2015-07-20 17:15:51 +00:00
*/
public function disable_dfw_feature_pointer () {
$screen = get_current_screen ();
2016-02-05 12:16:41 +00:00
if ( $screen && 'product' === $screen -> id && 'post' === $screen -> base ) {
2015-07-20 17:15:51 +00:00
remove_action ( 'admin_print_footer_scripts' , array ( 'WP_Internal_Pointers' , 'pointer_wp410_dfw' ) );
}
}
2016-02-19 19:04:36 +00:00
/**
* Removes products , orders , and coupons from the list of post types that support " View Mode " switching .
* View mode is seen on posts where you can switch between list or excerpt . Our post types don ' t support
* it , so we want to hide the useless UI from the screen options tab .
*
* @ since 2.6
* @ param array $post_types Array of post types supporting view mode
* @ return array Array of post types supporting view mode , without products , orders , and coupons
*/
public function disable_view_mode_options ( $post_types ) {
unset ( $post_types [ 'product' ], $post_types [ 'shop_order' ], $post_types [ 'shop_coupon' ] );
return $post_types ;
}
2016-06-03 13:07:41 +00:00
2016-10-11 11:44:54 +00:00
/**
* Show blank slate .
2017-05-15 11:50:52 +00:00
*
* @ param string $which
2016-10-11 11:44:54 +00:00
*/
2016-06-03 13:07:41 +00:00
public function maybe_render_blank_state ( $which ) {
global $post_type ;
2016-06-03 13:19:02 +00:00
if ( in_array ( $post_type , array ( 'shop_order' , 'product' , 'shop_coupon' ) ) && 'bottom' === $which ) {
$counts = ( array ) wp_count_posts ( $post_type );
2016-06-03 13:07:41 +00:00
unset ( $counts [ 'auto-draft' ] );
$count = array_sum ( $counts );
2016-06-03 13:19:02 +00:00
if ( 0 < $count ) {
2016-06-03 13:36:44 +00:00
return ;
2016-06-03 13:19:02 +00:00
}
echo '<div class="woocommerce-BlankState">' ;
switch ( $post_type ) {
case 'shop_order' :
?>
2016-06-03 13:07:41 +00:00
< h2 class = " woocommerce-BlankState-message " >< ? php _e ( 'When you receive a new order, it will appear here.' , 'woocommerce' ); ?> </h2>
2016-07-19 10:30:31 +00:00
< a class = " woocommerce-BlankState-cta button-primary button " target = " _blank " href = " https://docs.woocommerce.com/document/managing-orders/?utm_source=blankslate&utm_medium=product&utm_content=ordersdoc&utm_campaign=woocommerceplugin " >< ? php _e ( 'Learn more about orders' , 'woocommerce' ); ?> </a>
2016-06-03 13:19:02 +00:00
< ? php
break ;
case 'shop_coupon' :
?>
< h2 class = " woocommerce-BlankState-message " >< ? php _e ( 'Coupons are a great way to offer discounts and rewards to your customers. They will appear here once created.' , 'woocommerce' ); ?> </h2>
2016-07-19 10:30:31 +00:00
< a class = " woocommerce-BlankState-cta button-primary button " target = " _blank " href = " https://docs.woocommerce.com/document/coupon-management/?utm_source=blankslate&utm_medium=product&utm_content=couponsdoc&utm_campaign=woocommerceplugin " >< ? php _e ( 'Learn more about coupons' , 'woocommerce' ); ?> </a>
2016-06-03 13:19:02 +00:00
< ? php
break ;
case 'product' :
?>
< h2 class = " woocommerce-BlankState-message " >< ? php _e ( 'Ready to start selling something awesome?' , 'woocommerce' ); ?> </h2>
2016-06-07 15:14:21 +00:00
< a class = " woocommerce-BlankState-cta button-primary button " href = " <?php echo esc_url( admin_url( 'post-new.php?post_type=product&tutorial=true' ) ); ?> " >< ? php _e ( 'Create your first product!' , 'woocommerce' ); ?> </a>
2017-05-16 14:36:56 +00:00
< a class = " woocommerce-BlankState-cta button " href = " <?php echo esc_url( admin_url( 'edit.php?post_type=product&page=product_importer' ) ); ?> " >< ? php _e ( 'Import products from a CSV file' , 'woocommerce' ); ?> </a>
2016-06-03 13:19:02 +00:00
< ? php
break ;
2016-06-03 13:07:41 +00:00
}
2016-12-20 06:30:17 +00:00
echo '<style type="text/css">#posts-filter .wp-list-table, #posts-filter .tablenav.top, .tablenav.bottom .actions, .wrap .subsubsub { display: none; } </style></div>' ;
2016-06-03 13:19:02 +00:00
}
2016-06-03 13:07:41 +00:00
}
2016-10-11 11:44:54 +00:00
/**
* When editing the shop page , we should hide templates .
2017-05-15 11:50:52 +00:00
*
* @ param array $page_templates
* @ param $class
* @ param object $post
*
2016-10-11 11:44:54 +00:00
* @ return array
*/
public function hide_cpt_archive_templates ( $page_templates , $class , $post ) {
$shop_page_id = wc_get_page_id ( 'shop' );
if ( $post && absint ( $shop_page_id ) === absint ( $post -> ID ) ) {
$page_templates = array ();
}
return $page_templates ;
}
/**
* Show a notice above the CPT archive .
2017-05-15 11:50:52 +00:00
*
* @ param object $post
2016-10-11 11:44:54 +00:00
*/
public function show_cpt_archive_notice ( $post ) {
$shop_page_id = wc_get_page_id ( 'shop' );
if ( $post && absint ( $shop_page_id ) === absint ( $post -> ID ) ) {
?>
< div class = " notice notice-info " >
2016-10-27 17:36:24 +00:00
< p >< ? php printf ( __ ( 'This is the WooCommerce shop page. The shop page is a special archive that lists your products. <a href="%s">You can read more about this here</a>.' , 'woocommerce' ), 'https://docs.woocommerce.com/document/woocommerce-pages/#section-4' ); ?> </p>
2016-10-11 11:44:54 +00:00
</ div >
< ? php
}
}
2017-06-28 04:38:09 +00:00
/**
* Add a post display state for special WC pages in the page list table .
*
* @ param array $post_states An array of post display states .
* @ param WP_Post $post The current post object .
*/
public function add_display_post_states ( $post_states , $post ) {
if ( wc_get_page_id ( 'shop' ) === $post -> ID ) {
$post_states [ 'wc_page_for_shop' ] = __ ( 'Shop Page' , 'woocommerce' );
}
if ( wc_get_page_id ( 'cart' ) === $post -> ID ) {
$post_states [ 'wc_page_for_cart' ] = __ ( 'Cart Page' , 'woocommerce' );
}
if ( wc_get_page_id ( 'checkout' ) === $post -> ID ) {
$post_states [ 'wc_page_for_checkout' ] = __ ( 'Checkout Page' , 'woocommerce' );
}
if ( wc_get_page_id ( 'myaccount' ) === $post -> ID ) {
$post_states [ 'wc_page_for_myaccount' ] = __ ( 'My Account Page' , 'woocommerce' );
}
if ( wc_get_page_id ( 'terms' ) === $post -> ID ) {
2017-06-28 04:55:14 +00:00
$post_states [ 'wc_page_for_terms' ] = __ ( 'Terms and Conditions Page' , 'woocommerce' );
2017-06-28 04:38:09 +00:00
}
return $post_states ;
}
2013-07-24 16:01:36 +00:00
}
endif ;
2014-06-12 07:59:45 +00:00
new WC_Admin_Post_Types ();