'', // Unused. Messages start at index 1. 1 => sprintf( __('Product updated. View Product'), esc_url( get_permalink($post_ID) ) ), 2 => __('Custom field updated.'), 3 => __('Custom field deleted.'), 4 => __('Product updated.'), /* translators: %s: date and time of the revision */ 5 => isset($_GET['revision']) ? sprintf( __('Product restored to revision from %s'), wp_post_revision_title( (int) $_GET['revision'], false ) ) : false, 6 => sprintf( __('Product published. View Product'), esc_url( get_permalink($post_ID) ) ), 7 => __('Product saved.'), 8 => sprintf( __('Product submitted. Preview Product'), esc_url( add_query_arg( 'preview', 'true', get_permalink($post_ID) ) ) ), 9 => sprintf( __('Product scheduled for: %1$s. Preview Product'), // translators: Publish box date format, see http://php.net/date date_i18n( __( 'M j, Y @ G:i' ), strtotime( $post->post_date ) ), esc_url( get_permalink($post_ID) ) ), 10 => sprintf( __('Product draft updated. Preview Product'), esc_url( add_query_arg( 'preview', 'true', get_permalink($post_ID) ) ) ), ); return $messages; } /** * Custom columns **/ function jigoshop_edit_product_columns($columns) { $columns = array(); $columns["cb"] = ""; $columns["thumb"] = null; $columns["title"] = __("Title", 'jigoshop'); $columns["featured"] = __("Featured", 'jigoshop'); $columns["product-type"] = __("Type", 'jigoshop'); if( get_option('jigoshop_enable_sku', true) == 'yes' ) { $columns["product-type"] .= ' & ' . __("SKU", 'jigoshop'); } if ( get_option('jigoshop_manage_stock')=='yes' ) { $columns["stock"] = __("Stock", 'jigoshop'); } $columns["price"] = __("Price", 'jigoshop'); $columns["product-visibility"] = __("Visibility", 'jigoshop'); $columns["product-date"] = __("Date", 'jigoshop'); return $columns; } add_filter('manage_edit-product_columns', 'jigoshop_edit_product_columns'); function jigoshop_custom_product_columns($column) { global $post; $product = new jigoshop_product($post->ID); switch ($column) { case "thumb" : if( 'trash' != $post->post_status ) { echo ''; echo jigoshop_get_product_thumbnail( 'admin_product_list' ); echo ''; } else { echo jigoshop_get_product_thumbnail( 'admin_product_list' ); } break; case "price": echo $product->get_price_html(); break; case "featured" : $url = wp_nonce_url( admin_url('admin-ajax.php?action=jigoshop-feature-product&product_id=' . $post->ID) ); echo ''; if ($product->is_featured()) echo 'yes'; else echo 'no'; echo ''; break; case "stock" : if ( ! $product->is_type( 'grouped' ) && $product->is_in_stock() ) { if ( $product->managing_stock() ) { echo $product->stock.' '.__('In Stock', 'jigoshop'); } else { echo __('In Stock', 'jigoshop'); } } elseif ( $product->is_type( 'grouped' ) ) { echo __('Parent (no stock)', 'jigoshop'); } else { echo '' . __('Out of Stock', 'jigoshop') . ''; } break; case "product-type" : echo ucwords($product->product_type); echo '
'; if ( get_option('jigoshop_enable_sku', true) == 'yes' && $sku = get_post_meta( $post->ID, 'sku', true )) { echo $sku; } else { echo $post->ID; } break; case "product-date" : if ( '0000-00-00 00:00:00' == $post->post_date ) : $t_time = $h_time = __( 'Unpublished', 'jigoshop' ); $time_diff = 0; else : $t_time = get_the_time( __( 'Y/m/d g:i:s A', 'jigoshop' ) ); $m_time = $post->post_date; $time = get_post_time( 'G', true, $post ); $time_diff = time() - $time; if ( $time_diff > 0 && $time_diff < 24*60*60 ) $h_time = sprintf( __( '%s ago', 'jigoshop' ), human_time_diff( $time ) ); else $h_time = mysql2date( __( 'Y/m/d', 'jigoshop' ), $m_time ); endif; echo '' . apply_filters( 'post_date_column_time', $h_time, $post ) . '
'; if ( 'publish' == $post->post_status ) : _e( 'Published', 'jigoshop' ); elseif ( 'future' == $post->post_status ) : if ( $time_diff > 0 ) : echo '' . __( 'Missed schedule', 'jigoshop' ) . ''; else : _e( 'Scheduled', 'jigoshop' ); endif; else : _e( 'Draft', 'jigoshop' ); endif; break; case "product-visibility" : if ( $product->visibility ) : echo ($product->visibility == 'Hidden') ? ''.ucfirst($product->visibility).'' : ucfirst($product->visibility); endif; break; } } // Enable sorting for custom columns add_filter("manage_edit-product_sortable_columns", 'jigoshop_custom_product_sort'); function jigoshop_custom_product_sort( $columns ) { $custom = array( 'featured' => 'featured', 'price' => 'price', 'product-visibility' => 'visibility', 'product-date' => 'date' ); return wp_parse_args($custom, $columns); } // Product column orderby add_filter( 'request', 'jigoshop_custom_product_orderby' ); function jigoshop_custom_product_orderby( $vars ) { if (isset( $vars['orderby'] )) : if ( 'featured' == $vars['orderby'] ) : $vars = array_merge( $vars, array( 'meta_key' => 'featured', 'orderby' => 'meta_value' ) ); endif; if ( 'price' == $vars['orderby'] ) : $vars = array_merge( $vars, array( 'meta_key' => 'regular_price', 'orderby' => 'meta_value_num' ) ); endif; if ( 'visibility' == $vars['orderby'] ) : $vars = array_merge( $vars, array( 'meta_key' => 'visibility', 'orderby' => 'meta_value' ) ); endif; endif; return $vars; } /** * Filter products by category, uses slugs for option values. * Props to: Andrew Benbow - chromeorange.co.uk **/ add_action('restrict_manage_posts','jigoshop_products_by_category'); function jigoshop_products_by_category() { global $typenow, $wp_query; if ( $typenow=='product' ) jigoshop_product_dropdown_categories(); } /** * Filter products by type **/ add_action('restrict_manage_posts', 'jigoshop_filter_products_type'); function jigoshop_filter_products_type() { global $typenow, $wp_query; if ( $typenow != 'product' ) return false; // Get all active terms $terms = get_terms('product_type'); echo ""; } // NOTE: This causes a large spike in queries, however they are cached so the performance hit is minimal ~20ms -Rob add_action('manage_product_posts_custom_column', 'jigoshop_custom_product_columns', 2); function jigoshop_edit_order_columns($columns) { $columns = array(); //$columns["cb"] = ""; $columns["order_status"] = __("Status", 'jigoshop'); $columns["order_title"] = __("Order", 'jigoshop'); $columns["customer"] = __("Customer", 'jigoshop'); $columns["billing_address"] = __("Billing Address", 'jigoshop'); $columns["shipping_address"] = __("Shipping Address", 'jigoshop'); $columns["billing_and_shipping"] = __("Billing & Shipping", 'jigoshop'); $columns["total_cost"] = __("Order Cost", 'jigoshop'); return $columns; } add_filter('manage_edit-shop_order_columns', 'jigoshop_edit_order_columns'); add_action('manage_shop_order_posts_custom_column', 'jigoshop_custom_order_columns', 2); function jigoshop_custom_order_columns($column) { global $post; $order = new jigoshop_order($post->ID); switch ($column) { case "order_status" : echo sprintf( '%s', sanitize_title($order->status), __($order->status, 'jigoshop') ); break; case "order_title" : echo '' . sprintf(__('Order #%s', 'jigoshop'), $post->ID) . ''; echo ''; break; case "customer" : if ($order->user_id) $user_info = get_userdata($order->user_id); ?>
ID . '">#' . $user_info->ID . ' – '; if ($user_info->first_name || $user_info->last_name) echo $user_info->first_name . ' ' . $user_info->last_name; else echo $user_info->display_name; echo ''; else : _e('Guest', 'jigoshop'); endif; ?>
billing_email) : ?>
billing_email; ?>
billing_phone) : ?>
billing_phone; ?>
' . $order->billing_first_name . ' ' . $order->billing_last_name; if ($order->billing_company) echo ', ' . $order->billing_company; echo '
'; echo '' . $order->formatted_billing_address . ''; break; case "shipping_address" : if ($order->formatted_shipping_address) : echo '' . $order->shipping_first_name . ' ' . $order->shipping_last_name; if ($order->shipping_company) : echo ', ' . $order->shipping_company; endif; echo '
'; echo '' . $order->formatted_shipping_address . ''; else : echo '–'; endif; break; case "billing_and_shipping" : ?>
payment_method_title; ?>
shipping_service) : ?>
shipping_service, $order->shipping_method_title); ?>
shipping_method_title; ?>
order_subtotal_inc_tax) : ?> order_subtotal_inc_tax) : if ($order->order_shipping > 0) : ?>get_tax_classes() as $tax_class) : if ($order->tax_class_is_not_compound($tax_class)) : ?> order_shipping > 0) : ?>order_subtotal_inc_tax) : foreach ($order->get_tax_classes() as $tax_class) : if (!$order->tax_class_is_not_compound($tax_class)) : ?> get_tax_classes() as $tax_class) : ?> order_discount > 0) : ?>
order_subtotal); ?>
order_shipping); ?>
get_tax_class_for_display($tax_class) . ' (' . (float) $order->get_tax_rate($tax_class) . '%):'; ?> get_tax_amount($tax_class) ?>
order_subtotal_inc_tax); ?>
order_shipping); ?>
get_tax_class_for_display($tax_class) . ' (' . (float) $order->get_tax_rate($tax_class) . '%):'; ?> get_tax_amount($tax_class) ?>
get_tax_class_for_display($tax_class) . ' (' . (float) $order->get_tax_rate($tax_class) . '%):'; ?> get_tax_amount($tax_class) ?>
order_discount); ?>
order_total); ?>
query_vars['s'] ) ) return false; if ( ($wp->query_vars['post_type'] == 'product' || $wp->query_vars['post_type'] == 'shop_order') ) { if ( 'ID:' == substr( $wp->query_vars['s'], 0, 3 )) { $id = absint( substr( $wp->query_vars['s'], 3 ) ); if( ! $id ) return false; unset( $wp->query_vars['s'] ); $wp->query_vars['p'] = $id; } elseif( $wp->query_vars['post_type'] == 'product' && 'SKU:' == substr( $wp->query_vars['s'], 0, 4 ) ) { $sku = trim( substr( $wp->query_vars['s'], 4 ) ); if( ! $sku ) return false; $id = $wpdb->get_var('SELECT post_id FROM '.$wpdb->postmeta.' WHERE meta_key="sku" AND meta_value LIKE "%'.$sku.'%";'); if( ! $id ) return false; unset( $wp->query_vars['s'] ); $wp->query_vars['p'] = $id; $wp->query_vars['sku'] = $sku; } elseif( $wp->query_vars['post_type'] == 'shop_order' && 'PID:' == substr( $wp->query_vars['s'], 0, 4 ) ) { $id = absint( substr( $wp->query_vars['s'], 4 ) ); $id_length = strlen($id); // Get candidate orders $query = "'%s:2:\"id\";s:$id_length:\"$id\"%'"; $results = $wpdb->get_results( "SELECT post_id, meta_value FROM $wpdb->postmeta WHERE meta_key = 'order_items' AND meta_value LIKE $query" ); // Verify orders contain this product id $ids = array(); foreach ( $results as $result ) { $items = unserialize($result->meta_value); foreach ( $items as $item ) { if ( $item['id'] == $id ) { $ids[] = $result->post_id; break; } } } // Set search parameters unset( $wp->query_vars['s'] ); $wp->query_vars['post__in'] = $ids; $wp->query_vars['order_product_id'] = $id; } } } function jigoshop_admin_product_search_label($query) { global $pagenow, $typenow, $wp; if ( 'edit.php' != $pagenow ) return $query; if ( $typenow == 'product' || $typenow == 'shop_order' ) { $s = get_query_var( 's' ); if ( $s ) return $query; $sku = get_query_var( 'sku' ); if($sku) { $post_type = get_post_type_object($wp->query_vars['post_type']); return sprintf(__("[%s with SKU of %s]", 'jigoshop'), $post_type->labels->singular_name, $sku); } $p = get_query_var( 'p' ); if ($p) { $post_type = get_post_type_object($wp->query_vars['post_type']); return sprintf(__("[%s with ID of %d]", 'jigoshop'), $post_type->labels->singular_name, $p); } $order_id = get_query_var( 'order_product_id' ); if (get_query_var( 'post__in' )) { $post_type = get_post_type_object($wp->query_vars['post_type']); return sprintf(__("[%s with product ID of %d]", 'jigoshop'), $post_type->labels->singular_name, $order_id); } } return $query; } /** * Order page filters * */ function jigoshop_custom_order_views($views) { $jigoshop_orders = new jigoshop_orders(); $pending = (isset($_GET['shop_order_status']) && $_GET['shop_order_status'] == 'pending') ? 'current' : ''; $onhold = (isset($_GET['shop_order_status']) && $_GET['shop_order_status'] == 'on-hold') ? 'current' : ''; $processing = (isset($_GET['shop_order_status']) && $_GET['shop_order_status'] == 'processing') ? 'current' : ''; $completed = (isset($_GET['shop_order_status']) && $_GET['shop_order_status'] == 'completed') ? 'current' : ''; $cancelled = (isset($_GET['shop_order_status']) && $_GET['shop_order_status'] == 'cancelled') ? 'current' : ''; $refunded = (isset($_GET['shop_order_status']) && $_GET['shop_order_status'] == 'refunded') ? 'current' : ''; $views['pending'] = '' . __('Pending', 'jigoshop') . ' (' . $jigoshop_orders->pending_count . ')'; $views['onhold'] = '' . __('On-Hold', 'jigoshop') . ' (' . $jigoshop_orders->on_hold_count . ')'; $views['processing'] = '' . __('Processing', 'jigoshop') . ' (' . $jigoshop_orders->processing_count . ')'; $views['completed'] = '' . __('Completed', 'jigoshop') . ' (' . $jigoshop_orders->completed_count . ')'; $views['cancelled'] = '' . __('Cancelled', 'jigoshop') . ' (' . $jigoshop_orders->cancelled_count . ')'; $views['refunded'] = '' . __('Refunded', 'jigoshop') . ' (' . $jigoshop_orders->refunded_count . ')'; if ($pending || $onhold || $processing || $completed || $cancelled || $refunded) : $views['all'] = str_replace('current', '', $views['all']); endif; unset($views['publish']); if (isset($views['trash'])) : $trash = $views['trash']; unset($views['draft']); unset($views['trash']); $views['trash'] = $trash; endif; return $views; } add_filter('views_edit-shop_order', 'jigoshop_custom_order_views'); /** * Order page actions * */ function jigoshop_remove_row_actions($actions) { if (get_post_type() === 'shop_order') : unset($actions['view']); unset($actions['inline hide-if-no-js']); endif; return $actions; } add_filter('post_row_actions', 'jigoshop_remove_row_actions', 10, 1); /** * Order page views * */ function jigoshop_bulk_actions($actions) { return array(); } add_filter('bulk_actions-edit-shop_order', 'jigoshop_bulk_actions'); /** * Adds downloadable product support for thickbox * @todo: not sure if this is the best place for this? */ function jigoshop_media_upload_downloadable_product() { do_action('media_upload_file'); } add_action('media_upload_downloadable_product', 'jigoshop_media_upload_downloadable_product'); /** * Order messages * */ function jigoshop_post_updated_messages($messages) { if (get_post_type() === 'shop_order') : $messages['post'][1] = sprintf(__('Order updated.', 'jigoshop')); $messages['post'][4] = sprintf(__('Order updated.', 'jigoshop')); $messages['post'][6] = sprintf(__('Order published.', 'jigoshop')); $messages['post'][8] = sprintf(__('Order submitted.', 'jigoshop')); $messages['post'][10] = sprintf(__('Order draft updated.', 'jigoshop')); endif; return $messages; } add_filter( 'post_updated_messages', 'jigoshop_post_updated_messages' );