Skip to content

Commit

Permalink
refactor args for woocommerce_product_dropdown_categories
Browse files Browse the repository at this point in the history
  • Loading branch information
mikejolley committed Aug 20, 2013
1 parent 40a1cb4 commit aa470ad
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 17 deletions.
43 changes: 27 additions & 16 deletions includes/wc-term-functions.php
Expand Up @@ -18,38 +18,49 @@
* Stuck with this until a fix for http://core.trac.wordpress.org/ticket/13258
* We use a custom walker, just like WordPress does
*
* @access public
* @param int $show_counts (default: 1)
* @param int $hierarchical (default: 1)
* @param int $show_uncategorized (default: 1)
* @return string
*/
function woocommerce_product_dropdown_categories( $show_counts = 1, $hierarchical = 1, $show_uncategorized = 1, $orderby = '' ) {
function woocommerce_product_dropdown_categories( $args = array(), $deprecated_hierarchical = 1, $deprecated_show_uncategorized = 1, $deprecated_orderby = '' ) {
global $wp_query, $woocommerce;

$r = array();
$r['pad_counts'] = 1;
$r['hierarchical'] = $hierarchical;
$r['hide_empty'] = 1;
$r['show_count'] = $show_counts;
$r['selected'] = ( isset( $wp_query->query['product_cat'] ) ) ? $wp_query->query['product_cat'] : '';
$r['menu_order'] = false;
if ( ! is_array( $args ) ) {
_deprecated_argument( 'woocommerce_product_dropdown_categories()', '2.1', 'show_counts, hierarchical, show_uncategorized and orderby arguments are invalid - pass a single array of values instead.' );

$args['show_counts'] = $args;
$args['hierarchical'] = $deprecated_hierarchical;
$args['show_uncategorized'] = $deprecated_show_uncategorized;
$args['orderby'] = $deprecated_orderby;
}

$defaults = array(
'pad_counts' => 1,
'show_counts' => 1,
'hierarchical' => 1,
'hide_empty' => 1,
'show_uncategorized' => 1,
'orderby' => 'name',
'selected' => isset( $wp_query->query['product_cat'] ) ? $wp_query->query['product_cat'] : '',
'menu_order' => false
);

$args = wp_parse_args( $args, $defaults );

if ( $orderby == 'order' )
if ( $args['orderby'] == 'order' )
$r['menu_order'] = 'asc';
elseif ( $orderby )
$r['orderby'] = $orderby;

$terms = get_terms( 'product_cat', $r );
$terms = get_terms( 'product_cat', $args );

if ( ! $terms )
return;

$output = "<select name='product_cat' id='dropdown_product_cat'>";
$output .= '<option value="" ' . selected( isset( $_GET['product_cat'] ) ? $_GET['product_cat'] : '', '', false ) . '>'.__( 'Select a category', 'woocommerce' ).'</option>';
$output .= woocommerce_walk_category_dropdown_tree( $terms, 0, $r );
$output .= '<option value="" ' . selected( isset( $_GET['product_cat'] ) ? $_GET['product_cat'] : '', '', false ) . '>' . __( 'Select a category', 'woocommerce' ) . '</option>';
$output .= woocommerce_walk_category_dropdown_tree( $terms, 0, $args );

if ( $show_uncategorized )
if ( $args['show_uncategorized'] )
$output .= '<option value="0" ' . selected( isset( $_GET['product_cat'] ) ? $_GET['product_cat'] : '', '0', false ) . '>' . __( 'Uncategorized', 'woocommerce' ) . '</option>';

$output .="</select>";
Expand Down
7 changes: 6 additions & 1 deletion includes/widgets/class-wc-widget-product-categories.php
Expand Up @@ -104,7 +104,12 @@ public function widget( $args, $instance ) {
if ( $d ) {

// Stuck with this until a fix for http://core.trac.wordpress.org/ticket/13258
woocommerce_product_dropdown_categories( $c, $h, 0, $o );
woocommerce_product_dropdown_categories( array(
'show_counts' => $c,
'hierarchical' => $h,
'show_uncategorized' => 0,
'orderby' => $o
) );
?>
<script type='text/javascript'>
/* <![CDATA[ */
Expand Down

0 comments on commit aa470ad

Please sign in to comment.