New shop page/category archive display settings, and the ability to change display per-category. Closes #1600.

This commit is contained in:
Mike Jolley 2012-11-08 18:05:18 +00:00
parent 764b34a938
commit 784b7ae3b6
5 changed files with 133 additions and 48 deletions

View File

@ -73,6 +73,23 @@ if ( empty( $permalinks ) && $shop_page_id > 0 ) {
update_option( 'woocommerce_permalinks', $permalinks );
}
// Update subcat display settings
if ( get_option( 'woocommerce_shop_show_subcategories' ) == 'yes' ) {
if ( get_option( 'woocommerce_hide_products_when_showing_subcategories' ) == 'yes' ) {
update_option( 'woocommerce_shop_page_display', 'subcategories' );
} else {
update_option( 'woocommerce_shop_page_display', 'both' );
}
}
if ( get_option( 'woocommerce_show_subcategories' ) == 'yes' ) {
if ( get_option( 'woocommerce_hide_products_when_showing_subcategories' ) == 'yes' ) {
update_option( 'woocommerce_category_archive_display', 'subcategories' );
} else {
update_option( 'woocommerce_category_archive_display', 'both' );
}
}
// Now its time for the massive update to line items - move them to the new DB tables
// Reverse with UPDATE `wpwc_postmeta` SET meta_key = '_order_items' WHERE meta_key = '_order_items_old'
$order_item_rows = $wpdb->get_results( $wpdb->prepare( "

View File

@ -515,30 +515,35 @@ $woocommerce_settings['catalog'] = apply_filters('woocommerce_catalog_settings',
)),
'desc_tip' => true,
),
array(
'name' => __( 'Show subcategories', 'woocommerce' ),
'desc' => __( 'Show subcategories on category pages', 'woocommerce' ),
'id' => 'woocommerce_show_subcategories',
'std' => 'no',
'type' => 'checkbox',
'checkboxgroup' => 'start'
'name' => __( 'Shop page display', 'woocommerce' ),
'desc' => __( 'This controls what is shown on the product archive.', 'woocommerce' ),
'id' => 'woocommerce_shop_page_display',
'css' => 'min-width:150px;',
'std' => '',
'type' => 'select',
'options' => array(
'' => __( 'Show products', 'woocommerce' ),
'subcategories' => __( 'Show subcategories', 'woocommerce' ),
'both' => __( 'Show both', 'woocommerce' ),
),
'desc_tip' => true,
),
array(
'desc' => __( 'Show subcategories on the shop page', 'woocommerce' ),
'id' => 'woocommerce_shop_show_subcategories',
'std' => 'no',
'type' => 'checkbox',
'checkboxgroup' => ''
),
array(
'desc' => __( 'When showing subcategories, hide products', 'woocommerce' ),
'id' => 'woocommerce_hide_products_when_showing_subcategories',
'std' => 'no',
'type' => 'checkbox',
'checkboxgroup' => 'end'
'name' => __( 'Default category display', 'woocommerce' ),
'desc' => __( 'This controls what is shown on category archives.', 'woocommerce' ),
'id' => 'woocommerce_category_archive_display',
'css' => 'min-width:150px;',
'std' => '',
'type' => 'select',
'options' => array(
'' => __( 'Show products', 'woocommerce' ),
'subcategories' => __( 'Show subcategories', 'woocommerce' ),
'both' => __( 'Show both', 'woocommerce' ),
),
'desc_tip' => true,
),
array(

View File

@ -18,9 +18,18 @@ if ( ! defined( 'ABSPATH' ) ) exit; // Exit if accessed directly
* @access public
* @return void
*/
function woocommerce_add_category_thumbnail_field() {
function woocommerce_add_category_fields() {
global $woocommerce;
?>
<div class="form-field">
<label for="display_type"><?php _e( 'Display type', 'woocommerce' ); ?></label>
<select id="display_type" name="display_type" class="postform">
<option value=""><?php _e( 'Default', 'woocommerce' ); ?></option>
<option value="products"><?php _e( 'Products', 'woocommerce' ); ?></option>
<option value="subcategories"><?php _e( 'Subcategories', 'woocommerce' ); ?></option>
<option value="both"><?php _e( 'Both', 'woocommerce' ); ?></option>
</select>
</div>
<div class="form-field">
<label><?php _e( 'Thumbnail', 'woocommerce' ); ?></label>
<div id="product_cat_thumbnail" style="float:left;margin-right:10px;"><img src="<?php echo woocommerce_placeholder_img_src(); ?>" width="60px" height="60px" /></div>
@ -79,9 +88,7 @@ function woocommerce_add_category_thumbnail_field() {
<?php
}
add_action( 'product_cat_add_form_fields', 'woocommerce_add_category_thumbnail_field' );
add_action( 'product_cat_edit_form_fields', 'woocommerce_edit_category_thumbnail_field', 10,2 );
add_action( 'product_cat_add_form_fields', 'woocommerce_add_category_fields' );
/**
* Edit category thumbnail field.
@ -91,9 +98,10 @@ add_action( 'product_cat_edit_form_fields', 'woocommerce_edit_category_thumbnail
* @param mixed $taxonomy Taxonomy of the term being edited
* @return void
*/
function woocommerce_edit_category_thumbnail_field( $term, $taxonomy ) {
function woocommerce_edit_category_fields( $term, $taxonomy ) {
global $woocommerce;
$display_type = get_woocommerce_term_meta( $term->term_id, 'display_type', true );
$image = '';
$thumbnail_id = absint( get_woocommerce_term_meta( $term->term_id, 'thumbnail_id', true ) );
if ($thumbnail_id) :
@ -102,6 +110,17 @@ function woocommerce_edit_category_thumbnail_field( $term, $taxonomy ) {
$image = woocommerce_placeholder_img_src();
endif;
?>
<tr class="form-field">
<th scope="row" valign="top"><label><?php _e( 'Display type', 'woocommerce' ); ?></label></th>
<td>
<select id="display_type" name="display_type" class="postform">
<option value="" <?php selected( '', $display_type ); ?>><?php _e( 'Default', 'woocommerce' ); ?></option>
<option value="products" <?php selected( 'products', $display_type ); ?>><?php _e( 'Products', 'woocommerce' ); ?></option>
<option value="subcategories" <?php selected( 'subcategories', $display_type ); ?>><?php _e( 'Subcategories', 'woocommerce' ); ?></option>
<option value="both" <?php selected( 'both', $display_type ); ?>><?php _e( 'Both', 'woocommerce' ); ?></option>
</select>
</td>
</tr>
<tr class="form-field">
<th scope="row" valign="top"><label><?php _e( 'Thumbnail', 'woocommerce' ); ?></label></th>
<td>
@ -152,8 +171,11 @@ function woocommerce_edit_category_thumbnail_field( $term, $taxonomy ) {
<?php
}
add_action( 'product_cat_edit_form_fields', 'woocommerce_edit_category_fields', 10,2 );
/**
* woocommerce_category_thumbnail_field_save function.
* woocommerce_category_fields_save function.
*
* @access public
* @param mixed $term_id Term ID being saved
@ -161,13 +183,16 @@ function woocommerce_edit_category_thumbnail_field( $term, $taxonomy ) {
* @param mixed $taxonomy Taxonomy of the term being saved
* @return void
*/
function woocommerce_category_thumbnail_field_save( $term_id, $tt_id, $taxonomy ) {
function woocommerce_category_fields_save( $term_id, $tt_id, $taxonomy ) {
if ( isset( $_POST['display_type'] ) )
update_woocommerce_term_meta( $term_id, 'display_type', esc_attr( $_POST['display_type'] ) );
if ( isset( $_POST['product_cat_thumbnail_id'] ) )
update_woocommerce_term_meta( $term_id, 'thumbnail_id', $_POST['product_cat_thumbnail_id'] );
update_woocommerce_term_meta( $term_id, 'thumbnail_id', absint( $_POST['product_cat_thumbnail_id'] ) );
}
add_action( 'created_term', 'woocommerce_category_thumbnail_field_save', 10,3 );
add_action( 'edit_term', 'woocommerce_category_thumbnail_field_save', 10,3 );
add_action( 'created_term', 'woocommerce_category_fields_save', 10,3 );
add_action( 'edit_term', 'woocommerce_category_fields_save', 10,3 );
/**

View File

@ -176,6 +176,7 @@ Yes you can! Join in on our [GitHub repository](http://github.com/woothemes/wooc
* Feature - Added option to resend order emails, checkboxes select which one.
* Feature - New layered nav current filters widget. This lists active filters from all layered nav for de-selection.
* Feature - Added the option to sell products individually (only allow 1 in the cart).
* Feature - New shop page/category archive display settings, and the ability to change display per-category.
* Feature - Redone order item storage making them easier (and faster) to access for reporting, and querying purchases. Huge performance gains for reports. Order items are no longer serialised - they are stored in there own table with meta. Existing data can be be updated on upgrade.

View File

@ -1009,16 +1009,24 @@ if ( ! function_exists( 'woocommerce_products_will_display' ) ) {
if ( is_search() || is_filtered() || is_paged() )
return true;
if ( get_option( 'woocommerce_hide_products_when_showing_subcategories' ) == 'no' )
return true;
if ( is_product_category() && get_option( 'woocommerce_show_subcategories' ) == 'no' )
if ( is_shop() && get_option( 'woocommerce_shop_page_display' ) != 'subcategories' )
return true;
if ( is_shop() && get_option( 'woocommerce_shop_show_subcategories' ) == 'no' )
return true;
$term = get_queried_object();
if ( is_product_category() ) {
switch ( get_woocommerce_term_meta( $term->term_id, 'display_type', true ) ) {
case 'products' :
case 'both' :
return true;
break;
case '' :
if ( get_option( 'woocommerce_category_archive_display' ) != 'subcategories' )
return true;
break;
}
}
$term = get_queried_object();
$parent_id = empty( $term->term_id ) ? 0 : $term->term_id;
$has_children = $wpdb->get_col( $wpdb->prepare( "SELECT term_id FROM {$wpdb->term_taxonomy} WHERE parent = %d", $parent_id ) );
@ -1069,14 +1077,27 @@ if ( ! function_exists( 'woocommerce_product_subcategories' ) ) {
// Don't show when filtering, searching or when on page > 1 and ensure we're on a product archive
if ( is_search() || is_filtered() || is_paged() || ( ! is_product_category() && ! is_shop() ) ) return;
// Check categories are enabled
if ( is_product_category() && get_option( 'woocommerce_show_subcategories' ) == 'no' ) return;
if ( is_shop() && get_option( 'woocommerce_shop_show_subcategories' ) == 'no' ) return;
if ( is_shop() && get_option( 'woocommerce_shop_page_display' ) == '' ) return;
// Find the category + category parent, if applicable
$term = get_queried_object();
$parent_id = empty( $term->term_id ) ? 0 : $term->term_id;
if ( is_product_category() ) {
$display_type = get_woocommerce_term_meta( $term->term_id, 'display_type', true );
switch ( $display_type ) {
case 'products' :
return;
break;
case '' :
if ( get_option( 'woocommerce_category_archive_display' ) == '' )
return;
break;
}
}
// NOTE: using child_of instead of parent - this is not ideal but due to a WP bug ( http://core.trac.wordpress.org/ticket/15626 ) pad_counts won't work
$args = array(
@ -1113,12 +1134,28 @@ if ( ! function_exists( 'woocommerce_product_subcategories' ) ) {
}
// If we are hiding products disable the loop and pagination
if ( $product_category_found == true && get_option( 'woocommerce_hide_products_when_showing_subcategories' ) == 'yes' ) {
$wp_query->post_count = 0;
$wp_query->max_num_pages = 0;
}
if ( $product_category_found ) {
if ( is_product_category() ) {
$display_type = get_woocommerce_term_meta( $term->term_id, 'display_type', true );
switch ( $display_type ) {
case 'subcategories' :
$wp_query->post_count = 0;
$wp_query->max_num_pages = 0;
break;
case '' :
if ( get_option( 'woocommerce_category_archive_display' ) == 'subcategories' ) {
$wp_query->post_count = 0;
$wp_query->max_num_pages = 0;
}
break;
}
}
if ( is_shop() && get_option( 'woocommerce_shop_page_display' ) == 'subcategories' ) {
$wp_query->post_count = 0;
$wp_query->max_num_pages = 0;
}
echo esc_html( $after );
return true;
}