Preventing errors when adding a widget using the WP Customize
Fixed coding standards and used methods from WC_Widget for start and end the widget
This commit is contained in:
parent
eb3ebfd3e2
commit
24e17e36d3
|
@ -2,18 +2,47 @@
|
|||
/**
|
||||
* Abstract Widget Class
|
||||
*
|
||||
* @author WooThemes
|
||||
* @category Widgets
|
||||
* @package WooCommerce/Abstracts
|
||||
* @version 2.1.0
|
||||
* @extends WP_Widget
|
||||
* @author WooThemes
|
||||
* @category Widgets
|
||||
* @package WooCommerce/Abstracts
|
||||
* @version 2.3.0
|
||||
* @extends WP_Widget
|
||||
*/
|
||||
abstract class WC_Widget extends WP_Widget {
|
||||
|
||||
/**
|
||||
* CSS class
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
public $widget_cssclass;
|
||||
|
||||
/**
|
||||
* Widget description
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
public $widget_description;
|
||||
|
||||
/**
|
||||
* Widget ID
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
public $widget_id;
|
||||
|
||||
/**
|
||||
* Widget name
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
public $widget_name;
|
||||
|
||||
/**
|
||||
* Settings
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
public $settings;
|
||||
|
||||
/**
|
||||
|
@ -54,6 +83,7 @@ abstract class WC_Widget extends WP_Widget {
|
|||
|
||||
/**
|
||||
* Cache the widget
|
||||
*
|
||||
* @param array $args
|
||||
* @param string $content
|
||||
* @return string the content that was cached
|
||||
|
@ -75,26 +105,27 @@ abstract class WC_Widget extends WP_Widget {
|
|||
|
||||
/**
|
||||
* Output the html at the start of a widget
|
||||
*
|
||||
* @param array $args
|
||||
* @return string
|
||||
*/
|
||||
public function widget_start( $args, $instance ) {
|
||||
extract( $args );
|
||||
echo $args['before_widget'];
|
||||
|
||||
if ( $title = apply_filters( 'widget_title', $instance['title'], $instance, $this->id_base ) ) {
|
||||
echo $before_widget . $before_title . $title . $after_title;
|
||||
} else {
|
||||
echo $before_widget;
|
||||
$default = isset( $this->settings['title']['std'] ) ? $this->settings['title']['std'] : '';
|
||||
if ( $title = apply_filters( 'widget_title', empty( $instance['title'] ) ? $default : $instance['title'], $instance, $this->id_base ) ) {
|
||||
echo $args['before_title'] . $title . $args['after_title'];
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Output the html at the end of a widget
|
||||
*
|
||||
* @param array $args
|
||||
* @return string
|
||||
*/
|
||||
public function widget_end( $args ) {
|
||||
extract( $args );
|
||||
|
||||
echo $after_widget;
|
||||
echo $args['after_widget'];
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -141,11 +172,11 @@ abstract class WC_Widget extends WP_Widget {
|
|||
|
||||
foreach ( $this->settings as $key => $setting ) {
|
||||
|
||||
$value = isset( $instance[ $key ] ) ? $instance[ $key ] : $setting['std'];
|
||||
$value = isset( $instance[ $key ] ) ? $instance[ $key ] : $setting['std'];
|
||||
|
||||
switch ( $setting['type'] ) {
|
||||
|
||||
case "text" :
|
||||
case 'text' :
|
||||
?>
|
||||
<p>
|
||||
<label for="<?php echo $this->get_field_id( $key ); ?>"><?php echo $setting['label']; ?></label>
|
||||
|
@ -154,7 +185,7 @@ abstract class WC_Widget extends WP_Widget {
|
|||
<?php
|
||||
break;
|
||||
|
||||
case "number" :
|
||||
case 'number' :
|
||||
?>
|
||||
<p>
|
||||
<label for="<?php echo $this->get_field_id( $key ); ?>"><?php echo $setting['label']; ?></label>
|
||||
|
@ -163,7 +194,7 @@ abstract class WC_Widget extends WP_Widget {
|
|||
<?php
|
||||
break;
|
||||
|
||||
case "select" :
|
||||
case 'select' :
|
||||
?>
|
||||
<p>
|
||||
<label for="<?php echo $this->get_field_id( $key ); ?>"><?php echo $setting['label']; ?></label>
|
||||
|
@ -176,7 +207,7 @@ abstract class WC_Widget extends WP_Widget {
|
|||
<?php
|
||||
break;
|
||||
|
||||
case "checkbox" :
|
||||
case 'checkbox' :
|
||||
?>
|
||||
<p>
|
||||
<input id="<?php echo esc_attr( $this->get_field_id( $key ) ); ?>" name="<?php echo esc_attr( $this->get_field_name( $key ) ); ?>" type="checkbox" value="1" <?php checked( $value, 1 ); ?> />
|
||||
|
|
|
@ -4,11 +4,11 @@
|
|||
*
|
||||
* Displays shopping cart widget
|
||||
*
|
||||
* @author WooThemes
|
||||
* @category Widgets
|
||||
* @package WooCommerce/Widgets
|
||||
* @version 2.0.1
|
||||
* @extends WC_Widget
|
||||
* @author WooThemes
|
||||
* @category Widgets
|
||||
* @package WooCommerce/Widgets
|
||||
* @version 2.3.0
|
||||
* @extends WC_Widget
|
||||
*/
|
||||
|
||||
if ( ! defined( 'ABSPATH' ) ) {
|
||||
|
@ -37,6 +37,7 @@ class WC_Widget_Cart extends WC_Widget {
|
|||
'label' => __( 'Hide if cart is empty', 'woocommerce' )
|
||||
)
|
||||
);
|
||||
|
||||
parent::__construct();
|
||||
}
|
||||
|
||||
|
@ -44,34 +45,32 @@ class WC_Widget_Cart extends WC_Widget {
|
|||
* widget function.
|
||||
*
|
||||
* @see WP_Widget
|
||||
* @access public
|
||||
*
|
||||
* @param array $args
|
||||
* @param array $instance
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function widget( $args, $instance ) {
|
||||
if ( is_cart() || is_checkout() ) {
|
||||
return;
|
||||
}
|
||||
|
||||
extract( $args );
|
||||
|
||||
if ( is_cart() || is_checkout() ) return;
|
||||
|
||||
$title = apply_filters('widget_title', empty( $instance['title'] ) ? __( 'Cart', 'woocommerce' ) : $instance['title'], $instance, $this->id_base );
|
||||
$hide_if_empty = empty( $instance['hide_if_empty'] ) ? 0 : 1;
|
||||
|
||||
echo $before_widget;
|
||||
$this->widget_start( $args, $instance );
|
||||
|
||||
if ( $title )
|
||||
echo $before_title . $title . $after_title;
|
||||
|
||||
if ( $hide_if_empty )
|
||||
if ( $hide_if_empty ) {
|
||||
echo '<div class="hide_cart_widget_if_empty">';
|
||||
}
|
||||
|
||||
// Insert cart widget placeholder - code in woocommerce.js will update this on page load
|
||||
echo '<div class="widget_shopping_cart_content"></div>';
|
||||
|
||||
if ( $hide_if_empty )
|
||||
if ( $hide_if_empty ) {
|
||||
echo '</div>';
|
||||
}
|
||||
|
||||
echo $after_widget;
|
||||
$this->widget_end( $args );
|
||||
}
|
||||
}
|
||||
|
|
|
@ -2,11 +2,11 @@
|
|||
/**
|
||||
* Layered Navigation Fitlers Widget
|
||||
*
|
||||
* @author WooThemes
|
||||
* @category Widgets
|
||||
* @package WooCommerce/Widgets
|
||||
* @version 2.0.1
|
||||
* @extends WC_Widget
|
||||
* @author WooThemes
|
||||
* @category Widgets
|
||||
* @package WooCommerce/Widgets
|
||||
* @version 2.3.0
|
||||
* @extends WC_Widget
|
||||
*/
|
||||
|
||||
if ( ! defined( 'ABSPATH' ) ) {
|
||||
|
@ -30,6 +30,7 @@ class WC_Widget_Layered_Nav_Filters extends WC_Widget {
|
|||
'label' => __( 'Title', 'woocommerce' )
|
||||
)
|
||||
);
|
||||
|
||||
parent::__construct();
|
||||
}
|
||||
|
||||
|
@ -37,52 +38,48 @@ class WC_Widget_Layered_Nav_Filters extends WC_Widget {
|
|||
* widget function.
|
||||
*
|
||||
* @see WP_Widget
|
||||
* @access public
|
||||
*
|
||||
* @param array $args
|
||||
* @param array $instance
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function widget( $args, $instance ) {
|
||||
global $_chosen_attributes;
|
||||
|
||||
extract( $args );
|
||||
|
||||
if ( ! is_post_type_archive( 'product' ) && ! is_tax( get_object_taxonomies( 'product' ) ) )
|
||||
if ( ! is_post_type_archive( 'product' ) && ! is_tax( get_object_taxonomies( 'product' ) ) ) {
|
||||
return;
|
||||
}
|
||||
|
||||
$current_term = is_tax() ? get_queried_object()->term_id : '';
|
||||
$current_tax = is_tax() ? get_queried_object()->taxonomy : '';
|
||||
$title = isset( $instance['title'] ) ? $instance['title'] : '';
|
||||
$title = apply_filters( 'widget_title', $title, $instance, $this->id_base );
|
||||
$current_term = is_tax() ? get_queried_object()->term_id : '';
|
||||
$current_tax = is_tax() ? get_queried_object()->taxonomy : '';
|
||||
|
||||
// Price
|
||||
$min_price = isset( $_GET['min_price'] ) ? esc_attr( $_GET['min_price'] ) : 0;
|
||||
$max_price = isset( $_GET['max_price'] ) ? esc_attr( $_GET['max_price'] ) : 0;
|
||||
|
||||
if ( count( $_chosen_attributes ) > 0 || $min_price > 0 || $max_price > 0 ) {
|
||||
if ( 0 < count( $_chosen_attributes ) || 0 < $min_price || 0 < $max_price ) {
|
||||
|
||||
echo $before_widget;
|
||||
if ( $title ) {
|
||||
echo $before_title . $title . $after_title;
|
||||
}
|
||||
$this->widget_start( $args, $instance );
|
||||
|
||||
echo "<ul>";
|
||||
echo '<ul>';
|
||||
|
||||
// Attributes
|
||||
if (!is_null($_chosen_attributes)){
|
||||
if ( ! is_null( $_chosen_attributes ) ) {
|
||||
foreach ( $_chosen_attributes as $taxonomy => $data ) {
|
||||
|
||||
foreach ( $data['terms'] as $term_id ) {
|
||||
$term = get_term( $term_id, $taxonomy );
|
||||
$taxonomy_filter = str_replace( 'pa_', '', $taxonomy );
|
||||
$current_filter = ! empty( $_GET[ 'filter_' . $taxonomy_filter ] ) ? $_GET[ 'filter_' . $taxonomy_filter ] : '';
|
||||
$new_filter = array_map( 'absint', explode( ',', $current_filter ) );
|
||||
$new_filter = array_diff( $new_filter, array( $term_id ) );
|
||||
$term = get_term( $term_id, $taxonomy );
|
||||
$taxonomy_filter = str_replace( 'pa_', '', $taxonomy );
|
||||
$current_filter = ! empty( $_GET[ 'filter_' . $taxonomy_filter ] ) ? $_GET[ 'filter_' . $taxonomy_filter ] : '';
|
||||
$new_filter = array_map( 'absint', explode( ',', $current_filter ) );
|
||||
$new_filter = array_diff( $new_filter, array( $term_id ) );
|
||||
|
||||
$link = remove_query_arg( 'filter_' . $taxonomy_filter );
|
||||
|
||||
if ( sizeof( $new_filter ) > 0 )
|
||||
if ( sizeof( $new_filter ) > 0 ) {
|
||||
$link = add_query_arg( 'filter_' . $taxonomy_filter, implode( ',', $new_filter ), $link );
|
||||
}
|
||||
|
||||
echo '<li class="chosen"><a title="' . __( 'Remove filter', 'woocommerce' ) . '" href="' . esc_url( $link ) . '">' . $term->name . '</a></li>';
|
||||
}
|
||||
|
@ -99,9 +96,9 @@ class WC_Widget_Layered_Nav_Filters extends WC_Widget {
|
|||
echo '<li class="chosen"><a title="' . __( 'Remove filter', 'woocommerce' ) . '" href="' . esc_url( $link ) . '">' . __( 'Max', 'woocommerce' ) . ' ' . wc_price( $max_price ) . '</a></li>';
|
||||
}
|
||||
|
||||
echo "</ul>";
|
||||
echo '</ul>';
|
||||
|
||||
echo $after_widget;
|
||||
$this->widget_end( $args );
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -2,11 +2,11 @@
|
|||
/**
|
||||
* Layered Navigation Widget
|
||||
*
|
||||
* @author WooThemes
|
||||
* @category Widgets
|
||||
* @package WooCommerce/Widgets
|
||||
* @version 2.1.0
|
||||
* @extends WC_Widget
|
||||
* @author WooThemes
|
||||
* @category Widgets
|
||||
* @package WooCommerce/Widgets
|
||||
* @version 2.3.0
|
||||
* @extends WC_Widget
|
||||
*/
|
||||
|
||||
if ( ! defined( 'ABSPATH' ) ) {
|
||||
|
@ -31,13 +31,15 @@ class WC_Widget_Layered_Nav extends WC_Widget {
|
|||
* update function.
|
||||
*
|
||||
* @see WP_Widget->update
|
||||
* @access public
|
||||
*
|
||||
* @param array $new_instance
|
||||
* @param array $old_instance
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function update( $new_instance, $old_instance ) {
|
||||
$this->init_settings();
|
||||
|
||||
return parent::update( $new_instance, $old_instance );
|
||||
}
|
||||
|
||||
|
@ -45,51 +47,59 @@ class WC_Widget_Layered_Nav extends WC_Widget {
|
|||
* form function.
|
||||
*
|
||||
* @see WP_Widget->form
|
||||
* @access public
|
||||
*
|
||||
* @param array $instance
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function form( $instance ) {
|
||||
$this->init_settings();
|
||||
|
||||
parent::form( $instance );
|
||||
}
|
||||
|
||||
/**
|
||||
* Init settings after post types are registered
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function init_settings() {
|
||||
$attribute_array = array();
|
||||
$attribute_array = array();
|
||||
$attribute_taxonomies = wc_get_attribute_taxonomies();
|
||||
if ( $attribute_taxonomies )
|
||||
foreach ( $attribute_taxonomies as $tax )
|
||||
if ( taxonomy_exists( wc_attribute_taxonomy_name( $tax->attribute_name ) ) )
|
||||
$attribute_array[ $tax->attribute_name ] = $tax->attribute_name;
|
||||
|
||||
$this->settings = array(
|
||||
'title' => array(
|
||||
if ( $attribute_taxonomies ) {
|
||||
foreach ( $attribute_taxonomies as $tax ) {
|
||||
if ( taxonomy_exists( wc_attribute_taxonomy_name( $tax->attribute_name ) ) ) {
|
||||
$attribute_array[ $tax->attribute_name ] = $tax->attribute_name;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
$this->settings = array(
|
||||
'title' => array(
|
||||
'type' => 'text',
|
||||
'std' => __( 'Filter by', 'woocommerce' ),
|
||||
'label' => __( 'Title', 'woocommerce' )
|
||||
),
|
||||
'attribute' => array(
|
||||
'type' => 'select',
|
||||
'std' => '',
|
||||
'label' => __( 'Attribute', 'woocommerce' ),
|
||||
'type' => 'select',
|
||||
'std' => '',
|
||||
'label' => __( 'Attribute', 'woocommerce' ),
|
||||
'options' => $attribute_array
|
||||
),
|
||||
'display_type' => array(
|
||||
'type' => 'select',
|
||||
'std' => 'list',
|
||||
'label' => __( 'Display type', 'woocommerce' ),
|
||||
'type' => 'select',
|
||||
'std' => 'list',
|
||||
'label' => __( 'Display type', 'woocommerce' ),
|
||||
'options' => array(
|
||||
'list' => __( 'List', 'woocommerce' ),
|
||||
'dropdown' => __( 'Dropdown', 'woocommerce' )
|
||||
'list' => __( 'List', 'woocommerce' ),
|
||||
'dropdown' => __( 'Dropdown', 'woocommerce' )
|
||||
)
|
||||
),
|
||||
'query_type' => array(
|
||||
'type' => 'select',
|
||||
'std' => 'and',
|
||||
'label' => __( 'Query type', 'woocommerce' ),
|
||||
'type' => 'select',
|
||||
'std' => 'and',
|
||||
'label' => __( 'Query type', 'woocommerce' ),
|
||||
'options' => array(
|
||||
'and' => __( 'AND', 'woocommerce' ),
|
||||
'or' => __( 'OR', 'woocommerce' )
|
||||
|
@ -102,30 +112,30 @@ class WC_Widget_Layered_Nav extends WC_Widget {
|
|||
* widget function.
|
||||
*
|
||||
* @see WP_Widget
|
||||
* @access public
|
||||
*
|
||||
* @param array $args
|
||||
* @param array $instance
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function widget( $args, $instance ) {
|
||||
global $_chosen_attributes;
|
||||
|
||||
extract( $args );
|
||||
|
||||
if ( ! is_post_type_archive( 'product' ) && ! is_tax( get_object_taxonomies( 'product' ) ) )
|
||||
if ( ! is_post_type_archive( 'product' ) && ! is_tax( get_object_taxonomies( 'product' ) ) ) {
|
||||
return;
|
||||
}
|
||||
|
||||
$current_term = is_tax() ? get_queried_object()->term_id : '';
|
||||
$current_tax = is_tax() ? get_queried_object()->taxonomy : '';
|
||||
$title = apply_filters('widget_title', $instance['title'], $instance, $this->id_base);
|
||||
$taxonomy = isset( $instance['attribute'] ) ? wc_attribute_taxonomy_name($instance['attribute']) : '';
|
||||
$query_type = isset( $instance['query_type'] ) ? $instance['query_type'] : 'and';
|
||||
$display_type = isset( $instance['display_type'] ) ? $instance['display_type'] : 'list';
|
||||
$current_term = is_tax() ? get_queried_object()->term_id : '';
|
||||
$current_tax = is_tax() ? get_queried_object()->taxonomy : '';
|
||||
$taxonomy = isset( $instance['attribute'] ) ? wc_attribute_taxonomy_name( $instance['attribute'] ) : $this->settings['attribute']['std'];
|
||||
$query_type = isset( $instance['query_type'] ) ? $instance['query_type'] : $this->settings['query_type']['std'];
|
||||
$display_type = isset( $instance['display_type'] ) ? $instance['display_type'] : $this->settings['display_type']['std'];
|
||||
|
||||
if ( ! taxonomy_exists( $taxonomy ) )
|
||||
if ( ! taxonomy_exists( $taxonomy ) ) {
|
||||
return;
|
||||
}
|
||||
|
||||
$get_terms_args = array( 'hide_empty' => '1' );
|
||||
$get_terms_args = array( 'hide_empty' => '1' );
|
||||
|
||||
$orderby = wc_attribute_orderby( $taxonomy );
|
||||
|
||||
|
@ -146,19 +156,20 @@ class WC_Widget_Layered_Nav extends WC_Widget {
|
|||
|
||||
$terms = get_terms( $taxonomy, $get_terms_args );
|
||||
|
||||
if ( count( $terms ) > 0 ) {
|
||||
if ( 0 < count( $terms ) ) {
|
||||
|
||||
ob_start();
|
||||
|
||||
$found = false;
|
||||
|
||||
echo $before_widget . $before_title . $title . $after_title;
|
||||
$this->widget_start( $args, $instance );
|
||||
|
||||
// Force found when option is selected - do not force found on taxonomy attributes
|
||||
if ( ! is_tax() && is_array( $_chosen_attributes ) && array_key_exists( $taxonomy, $_chosen_attributes ) )
|
||||
if ( ! is_tax() && is_array( $_chosen_attributes ) && array_key_exists( $taxonomy, $_chosen_attributes ) ) {
|
||||
$found = true;
|
||||
}
|
||||
|
||||
if ( $display_type == 'dropdown' ) {
|
||||
if ( 'dropdown' == $display_type ) {
|
||||
|
||||
// skip when viewing the taxonomy
|
||||
if ( $current_tax && $taxonomy == $current_tax ) {
|
||||
|
@ -173,13 +184,14 @@ class WC_Widget_Layered_Nav extends WC_Widget {
|
|||
|
||||
echo '<select class="dropdown_layered_nav_' . $taxonomy_filter . '">';
|
||||
|
||||
echo '<option value="">' . sprintf( __( 'Any %s', 'woocommerce' ), wc_attribute_label( $taxonomy ) ) .'</option>';
|
||||
echo '<option value="">' . sprintf( __( 'Any %s', 'woocommerce' ), wc_attribute_label( $taxonomy ) ) . '</option>';
|
||||
|
||||
foreach ( $terms as $term ) {
|
||||
|
||||
// If on a term page, skip that term in widget list
|
||||
if ( $term->term_id == $current_term )
|
||||
if ( $term->term_id == $current_term ) {
|
||||
continue;
|
||||
}
|
||||
|
||||
// Get count based on current view - uses transients
|
||||
$transient_name = 'wc_ln_count_' . md5( sanitize_key( $taxonomy ) . sanitize_key( $term->term_taxonomy_id ) );
|
||||
|
@ -194,47 +206,50 @@ class WC_Widget_Layered_Nav extends WC_Widget {
|
|||
$option_is_set = ( isset( $_chosen_attributes[ $taxonomy ] ) && in_array( $term->term_id, $_chosen_attributes[ $taxonomy ]['terms'] ) );
|
||||
|
||||
// If this is an AND query, only show options with count > 0
|
||||
if ( $query_type == 'and' ) {
|
||||
if ( 'and' == $query_type ) {
|
||||
|
||||
$count = sizeof( array_intersect( $_products_in_term, WC()->query->filtered_product_ids ) );
|
||||
|
||||
if ( $count > 0 )
|
||||
if ( 0 < $count ) {
|
||||
$found = true;
|
||||
}
|
||||
|
||||
if ( $count == 0 && ! $option_is_set )
|
||||
if ( 0 == $count && ! $option_is_set ) {
|
||||
continue;
|
||||
}
|
||||
|
||||
// If this is an OR query, show all options so search can be expanded
|
||||
} else {
|
||||
|
||||
$count = sizeof( array_intersect( $_products_in_term, WC()->query->unfiltered_product_ids ) );
|
||||
|
||||
if ( $count > 0 )
|
||||
if ( 0 < $count ) {
|
||||
$found = true;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
echo '<option value="' . esc_attr( $term->term_id ) . '" '.selected( isset( $_GET[ 'filter_' . $taxonomy_filter ] ) ? $_GET[ 'filter_' .$taxonomy_filter ] : '' , $term->term_id, false ) . '>' . $term->name . '</option>';
|
||||
echo '<option value="' . esc_attr( $term->term_id ) . '" ' . selected( isset( $_GET[ 'filter_' . $taxonomy_filter ] ) ? $_GET[ 'filter_' .$taxonomy_filter ] : '' , $term->term_id, false ) . '>' . $term->name . '</option>';
|
||||
}
|
||||
|
||||
echo '</select>';
|
||||
|
||||
wc_enqueue_js("
|
||||
wc_enqueue_js( "
|
||||
|
||||
jQuery('.dropdown_layered_nav_$taxonomy_filter').change(function(){
|
||||
|
||||
location.href = '" . esc_url_raw( preg_replace( '%\/page/[0-9]+%', '', add_query_arg('filtering', '1', remove_query_arg( array( 'page', 'filter_' . $taxonomy_filter ) ) ) ) ) . "&filter_$taxonomy_filter=' + jQuery(this).val();
|
||||
location.href = '" . esc_url_raw( preg_replace( '%\/page/[0-9]+%', '', add_query_arg( 'filtering', '1', remove_query_arg( array( 'page', 'filter_' . $taxonomy_filter ) ) ) ) ) . "&filter_$taxonomy_filter=' + jQuery(this).val();
|
||||
|
||||
});
|
||||
|
||||
");
|
||||
" );
|
||||
|
||||
}
|
||||
|
||||
} else {
|
||||
|
||||
// List display
|
||||
echo "<ul>";
|
||||
echo '<ul>';
|
||||
|
||||
foreach ( $terms as $term ) {
|
||||
|
||||
|
@ -251,41 +266,46 @@ class WC_Widget_Layered_Nav extends WC_Widget {
|
|||
$option_is_set = ( isset( $_chosen_attributes[ $taxonomy ] ) && in_array( $term->term_id, $_chosen_attributes[ $taxonomy ]['terms'] ) );
|
||||
|
||||
// skip the term for the current archive
|
||||
if ( $current_term == $term->term_id )
|
||||
if ( $current_term == $term->term_id ) {
|
||||
continue;
|
||||
}
|
||||
|
||||
// If this is an AND query, only show options with count > 0
|
||||
if ( $query_type == 'and' ) {
|
||||
if ( 'and' == $query_type ) {
|
||||
|
||||
$count = sizeof( array_intersect( $_products_in_term, WC()->query->filtered_product_ids ) );
|
||||
|
||||
if ( $count > 0 && $current_term !== $term->term_id )
|
||||
if ( 0 < $count && $current_term !== $term->term_id ) {
|
||||
$found = true;
|
||||
}
|
||||
|
||||
if ( $count == 0 && ! $option_is_set )
|
||||
if ( 0 == $count && ! $option_is_set ) {
|
||||
continue;
|
||||
}
|
||||
|
||||
// If this is an OR query, show all options so search can be expanded
|
||||
} else {
|
||||
|
||||
$count = sizeof( array_intersect( $_products_in_term, WC()->query->unfiltered_product_ids ) );
|
||||
|
||||
if ( $count > 0 )
|
||||
$found = true;
|
||||
$count = sizeof( array_intersect( $_products_in_term, WC()->query->unfiltered_product_ids ) );
|
||||
|
||||
if ( 0 < $count ) {
|
||||
$found = true;
|
||||
}
|
||||
}
|
||||
|
||||
$arg = 'filter_' . sanitize_title( $instance['attribute'] );
|
||||
|
||||
$current_filter = ( isset( $_GET[ $arg ] ) ) ? explode( ',', $_GET[ $arg ] ) : array();
|
||||
|
||||
if ( ! is_array( $current_filter ) )
|
||||
if ( ! is_array( $current_filter ) ) {
|
||||
$current_filter = array();
|
||||
}
|
||||
|
||||
$current_filter = array_map( 'esc_attr', $current_filter );
|
||||
|
||||
if ( ! in_array( $term->term_id, $current_filter ) )
|
||||
if ( ! in_array( $term->term_id, $current_filter ) ) {
|
||||
$current_filter[] = $term->term_id;
|
||||
}
|
||||
|
||||
// Base Link decided by current page
|
||||
if ( defined( 'SHOP_IS_ON_FRONT' ) ) {
|
||||
|
@ -310,25 +330,30 @@ class WC_Widget_Layered_Nav extends WC_Widget {
|
|||
// Remove pa_ and sanitize
|
||||
$filter_name = sanitize_title( str_replace( 'pa_', '', $name ) );
|
||||
|
||||
if ( ! empty( $data['terms'] ) )
|
||||
if ( ! empty( $data['terms'] ) ) {
|
||||
$link = add_query_arg( 'filter_' . $filter_name, implode( ',', $data['terms'] ), $link );
|
||||
}
|
||||
|
||||
if ( $data['query_type'] == 'or' )
|
||||
if ( 'or' == $data['query_type'] ) {
|
||||
$link = add_query_arg( 'query_type_' . $filter_name, 'or', $link );
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Min/Max
|
||||
if ( isset( $_GET['min_price'] ) )
|
||||
if ( isset( $_GET['min_price'] ) ) {
|
||||
$link = add_query_arg( 'min_price', $_GET['min_price'], $link );
|
||||
}
|
||||
|
||||
if ( isset( $_GET['max_price'] ) )
|
||||
if ( isset( $_GET['max_price'] ) ) {
|
||||
$link = add_query_arg( 'max_price', $_GET['max_price'], $link );
|
||||
}
|
||||
|
||||
// Orderby
|
||||
if ( isset( $_GET['orderby'] ) )
|
||||
if ( isset( $_GET['orderby'] ) ) {
|
||||
$link = add_query_arg( 'orderby', $_GET['orderby'], $link );
|
||||
}
|
||||
|
||||
// Current Filter = this widget
|
||||
if ( isset( $_chosen_attributes[ $taxonomy ] ) && is_array( $_chosen_attributes[ $taxonomy ]['terms'] ) && in_array( $term->term_id, $_chosen_attributes[ $taxonomy ]['terms'] ) ) {
|
||||
|
@ -349,16 +374,19 @@ class WC_Widget_Layered_Nav extends WC_Widget {
|
|||
}
|
||||
|
||||
// Search Arg
|
||||
if ( get_search_query() )
|
||||
if ( get_search_query() ) {
|
||||
$link = add_query_arg( 's', get_search_query(), $link );
|
||||
}
|
||||
|
||||
// Post Type Arg
|
||||
if ( isset( $_GET['post_type'] ) )
|
||||
if ( isset( $_GET['post_type'] ) ) {
|
||||
$link = add_query_arg( 'post_type', $_GET['post_type'], $link );
|
||||
}
|
||||
|
||||
// Query type Arg
|
||||
if ( $query_type == 'or' && ! ( sizeof( $current_filter ) == 1 && isset( $_chosen_attributes[ $taxonomy ]['terms'] ) && is_array( $_chosen_attributes[ $taxonomy ]['terms'] ) && in_array( $term->term_id, $_chosen_attributes[ $taxonomy ]['terms'] ) ) )
|
||||
if ( $query_type == 'or' && ! ( sizeof( $current_filter ) == 1 && isset( $_chosen_attributes[ $taxonomy ]['terms'] ) && is_array( $_chosen_attributes[ $taxonomy ]['terms'] ) && in_array( $term->term_id, $_chosen_attributes[ $taxonomy ]['terms'] ) ) ) {
|
||||
$link = add_query_arg( 'query_type_' . sanitize_title( $instance['attribute'] ), 'or', $link );
|
||||
}
|
||||
|
||||
echo '<li ' . $class . '>';
|
||||
|
||||
|
@ -368,20 +396,21 @@ class WC_Widget_Layered_Nav extends WC_Widget {
|
|||
|
||||
echo ( $count > 0 || $option_is_set ) ? '</a>' : '</span>';
|
||||
|
||||
echo ' <span class="count">(' . $count . ')</span></li>';
|
||||
echo ' <small class="count">' . $count . '</small></li>';
|
||||
|
||||
}
|
||||
|
||||
echo "</ul>";
|
||||
echo '</ul>';
|
||||
|
||||
} // End display type conditional
|
||||
|
||||
echo $after_widget;
|
||||
$this->widget_end( $args );
|
||||
|
||||
if ( ! $found )
|
||||
if ( ! $found ) {
|
||||
ob_end_clean();
|
||||
else
|
||||
} else {
|
||||
echo ob_get_clean();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -4,11 +4,11 @@
|
|||
*
|
||||
* Generates a range slider to filter products by price.
|
||||
*
|
||||
* @author WooThemes
|
||||
* @category Widgets
|
||||
* @package WooCommerce/Widgets
|
||||
* @version 2.1.0
|
||||
* @extends WC_Widget
|
||||
* @author WooThemes
|
||||
* @category Widgets
|
||||
* @package WooCommerce/Widgets
|
||||
* @version 2.3.0
|
||||
* @extends WC_Widget
|
||||
*/
|
||||
|
||||
if ( ! defined( 'ABSPATH' ) ) {
|
||||
|
@ -32,6 +32,7 @@ class WC_Widget_Price_Filter extends WC_Widget {
|
|||
'label' => __( 'Title', 'woocommerce' )
|
||||
)
|
||||
);
|
||||
|
||||
parent::__construct();
|
||||
}
|
||||
|
||||
|
@ -39,16 +40,15 @@ class WC_Widget_Price_Filter extends WC_Widget {
|
|||
* widget function.
|
||||
*
|
||||
* @see WP_Widget
|
||||
* @access public
|
||||
*
|
||||
* @param array $args
|
||||
* @param array $instance
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function widget( $args, $instance ) {
|
||||
global $_chosen_attributes, $wpdb, $wp;
|
||||
|
||||
extract( $args );
|
||||
|
||||
if ( ! is_post_type_archive( 'product' ) && ! is_tax( get_object_taxonomies( 'product' ) ) ) {
|
||||
return;
|
||||
}
|
||||
|
@ -62,8 +62,6 @@ class WC_Widget_Price_Filter extends WC_Widget {
|
|||
|
||||
wp_enqueue_script( 'wc-price-slider' );
|
||||
|
||||
$title = apply_filters( 'widget_title', $instance['title'], $instance, $this->id_base );
|
||||
|
||||
// Remember current filters/search
|
||||
$fields = '';
|
||||
|
||||
|
@ -87,21 +85,22 @@ class WC_Widget_Price_Filter extends WC_Widget {
|
|||
$fields .= '<input type="hidden" name="orderby" value="' . esc_attr( $_GET['orderby'] ) . '" />';
|
||||
}
|
||||
|
||||
if ( $_chosen_attributes ) foreach ( $_chosen_attributes as $attribute => $data ) {
|
||||
if ( $_chosen_attributes ) {
|
||||
foreach ( $_chosen_attributes as $attribute => $data ) {
|
||||
$taxonomy_filter = 'filter_' . str_replace( 'pa_', '', $attribute );
|
||||
|
||||
$taxonomy_filter = 'filter_' . str_replace( 'pa_', '', $attribute );
|
||||
$fields .= '<input type="hidden" name="' . esc_attr( $taxonomy_filter ) . '" value="' . esc_attr( implode( ',', $data['terms'] ) ) . '" />';
|
||||
|
||||
$fields .= '<input type="hidden" name="' . esc_attr( $taxonomy_filter ) . '" value="' . esc_attr( implode( ',', $data['terms'] ) ) . '" />';
|
||||
|
||||
if ( $data['query_type'] == 'or' ) {
|
||||
$fields .= '<input type="hidden" name="' . esc_attr( str_replace( 'pa_', 'query_type_', $attribute ) ) . '" value="or" />';
|
||||
if ( 'or' == $data['query_type'] ) {
|
||||
$fields .= '<input type="hidden" name="' . esc_attr( str_replace( 'pa_', 'query_type_', $attribute ) ) . '" value="or" />';
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
$min = $max = 0;
|
||||
$post_min = $post_max = '';
|
||||
|
||||
if ( sizeof( WC()->query->layered_nav_product_ids ) === 0 ) {
|
||||
if ( 0 === sizeof( WC()->query->layered_nav_product_ids ) ) {
|
||||
$min = floor( $wpdb->get_var(
|
||||
$wpdb->prepare('
|
||||
SELECT min(meta_value + 0)
|
||||
|
@ -157,9 +156,9 @@ class WC_Widget_Price_Filter extends WC_Widget {
|
|||
return;
|
||||
}
|
||||
|
||||
echo $before_widget . $before_title . $title . $after_title;
|
||||
$this->widget_start( $args, $instance );
|
||||
|
||||
if ( get_option( 'permalink_structure' ) == '' ) {
|
||||
if ( '' == get_option( 'permalink_structure' ) ) {
|
||||
$form_action = remove_query_arg( array( 'page', 'paged' ), add_query_arg( $wp->query_string, '', home_url( $wp->request ) ) );
|
||||
} else {
|
||||
$form_action = preg_replace( '%\/page/[0-9]+%', '', home_url( $wp->request ) );
|
||||
|
@ -181,6 +180,6 @@ class WC_Widget_Price_Filter extends WC_Widget {
|
|||
</div>
|
||||
</form>';
|
||||
|
||||
echo $after_widget;
|
||||
$this->widget_end( $args );
|
||||
}
|
||||
}
|
||||
|
|
|
@ -2,11 +2,11 @@
|
|||
/**
|
||||
* Product Categories Widget
|
||||
*
|
||||
* @author WooThemes
|
||||
* @category Widgets
|
||||
* @package WooCommerce/Widgets
|
||||
* @version 2.1.0
|
||||
* @extends WC_Widget
|
||||
* @author WooThemes
|
||||
* @category Widgets
|
||||
* @package WooCommerce/Widgets
|
||||
* @version 2.3.0
|
||||
* @extends WC_Widget
|
||||
*/
|
||||
|
||||
if ( ! defined( 'ABSPATH' ) ) {
|
||||
|
@ -15,7 +15,18 @@ if ( ! defined( 'ABSPATH' ) ) {
|
|||
|
||||
class WC_Widget_Product_Categories extends WC_Widget {
|
||||
|
||||
/**
|
||||
* Category ancestors
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
public $cat_ancestors;
|
||||
|
||||
/**
|
||||
* Current Category
|
||||
*
|
||||
* @var bool
|
||||
*/
|
||||
public $current_cat;
|
||||
|
||||
/**
|
||||
|
@ -62,6 +73,7 @@ class WC_Widget_Product_Categories extends WC_Widget {
|
|||
'label' => __( 'Only show children of the current category', 'woocommerce' )
|
||||
)
|
||||
);
|
||||
|
||||
parent::__construct();
|
||||
}
|
||||
|
||||
|
@ -69,22 +81,20 @@ class WC_Widget_Product_Categories extends WC_Widget {
|
|||
* widget function.
|
||||
*
|
||||
* @see WP_Widget
|
||||
* @access public
|
||||
*
|
||||
* @param array $args
|
||||
* @param array $instance
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function widget( $args, $instance ) {
|
||||
extract( $args );
|
||||
|
||||
global $wp_query, $post;
|
||||
|
||||
$title = apply_filters( 'widget_title', $instance['title'], $instance, $this->id_base );
|
||||
$c = ! empty( $instance['count'] );
|
||||
$h = ! empty( $instance['hierarchical'] );
|
||||
$s = ! empty( $instance['show_children_only'] );
|
||||
$d = ! empty( $instance['dropdown'] );
|
||||
$o = $instance['orderby'] ? $instance['orderby'] : 'order';
|
||||
$c = isset( $instance['count'] ) ? $instance['count'] : $this->settings['count']['std'];
|
||||
$h = isset( $instance['hierarchical'] ) ? $instance['hierarchical'] : $this->settings['hierarchical']['std'];
|
||||
$s = isset( $instance['show_children_only'] ) ? $instance['show_children_only'] : $this->settings['show_children_only']['std'];
|
||||
$d = isset( $instance['dropdown'] ) ? $instance['dropdown'] : $this->settings['dropdown']['std'];
|
||||
$o = isset( $instance['orderby'] ) ? $instance['orderby'] : $this->settings['orderby']['std'];
|
||||
$dropdown_args = array( 'hide_empty' => false );
|
||||
$list_args = array( 'show_count' => $c, 'hierarchical' => $h, 'taxonomy' => 'product_cat', 'hide_empty' => false );
|
||||
|
||||
|
@ -100,12 +110,12 @@ class WC_Widget_Product_Categories extends WC_Widget {
|
|||
$this->current_cat = false;
|
||||
$this->cat_ancestors = array();
|
||||
|
||||
if ( is_tax('product_cat') ) {
|
||||
if ( is_tax( 'product_cat' ) ) {
|
||||
|
||||
$this->current_cat = $wp_query->queried_object;
|
||||
$this->cat_ancestors = get_ancestors( $this->current_cat->term_id, 'product_cat' );
|
||||
|
||||
} elseif ( is_singular('product') ) {
|
||||
} elseif ( is_singular( 'product' ) ) {
|
||||
|
||||
$product_category = wc_get_product_terms( $post->ID, 'product_cat', array( 'orderby' => 'parent' ) );
|
||||
|
||||
|
@ -180,15 +190,10 @@ class WC_Widget_Product_Categories extends WC_Widget {
|
|||
$list_args['hierarchical'] = 1;
|
||||
}
|
||||
|
||||
echo $before_widget;
|
||||
|
||||
if ( $title ) {
|
||||
echo $before_title . $title . $after_title;
|
||||
}
|
||||
$this->widget_start( $args, $instance );
|
||||
|
||||
// Dropdown
|
||||
if ( $d ) {
|
||||
|
||||
$dropdown_defaults = array(
|
||||
'show_counts' => $c,
|
||||
'hierarchical' => $h,
|
||||
|
@ -201,13 +206,13 @@ class WC_Widget_Product_Categories extends WC_Widget {
|
|||
// Stuck with this until a fix for http://core.trac.wordpress.org/ticket/13258
|
||||
wc_product_dropdown_categories( apply_filters( 'woocommerce_product_categories_widget_dropdown_args', $dropdown_args ) );
|
||||
|
||||
wc_enqueue_js("
|
||||
wc_enqueue_js( "
|
||||
jQuery('.dropdown_product_cat').change(function(){
|
||||
if(jQuery(this).val() != '') {
|
||||
location.href = '" . home_url() . "/?product_cat=' + jQuery(this).val();
|
||||
}
|
||||
});
|
||||
");
|
||||
" );
|
||||
|
||||
// List
|
||||
} else {
|
||||
|
@ -228,6 +233,6 @@ class WC_Widget_Product_Categories extends WC_Widget {
|
|||
echo '</ul>';
|
||||
}
|
||||
|
||||
echo $after_widget;
|
||||
$this->widget_end( $args );
|
||||
}
|
||||
}
|
||||
|
|
|
@ -2,11 +2,11 @@
|
|||
/**
|
||||
* Product Search Widget
|
||||
*
|
||||
* @author WooThemes
|
||||
* @category Widgets
|
||||
* @package WooCommerce/Widgets
|
||||
* @version 2.1.0
|
||||
* @extends WC_Widget
|
||||
* @author WooThemes
|
||||
* @category Widgets
|
||||
* @package WooCommerce/Widgets
|
||||
* @version 2.3.0
|
||||
* @extends WC_Widget
|
||||
*/
|
||||
|
||||
if ( ! defined( 'ABSPATH' ) ) {
|
||||
|
@ -26,10 +26,11 @@ class WC_Widget_Product_Search extends WC_Widget {
|
|||
$this->settings = array(
|
||||
'title' => array(
|
||||
'type' => 'text',
|
||||
'std' => __( 'Search Products', 'woocommerce' ),
|
||||
'std' => '',
|
||||
'label' => __( 'Title', 'woocommerce' )
|
||||
)
|
||||
);
|
||||
|
||||
parent::__construct();
|
||||
}
|
||||
|
||||
|
@ -37,24 +38,17 @@ class WC_Widget_Product_Search extends WC_Widget {
|
|||
* widget function.
|
||||
*
|
||||
* @see WP_Widget
|
||||
* @access public
|
||||
*
|
||||
* @param array $args
|
||||
* @param array $instance
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
function widget( $args, $instance ) {
|
||||
extract( $args );
|
||||
|
||||
$title = $instance['title'];
|
||||
$title = apply_filters('widget_title', $title, $instance, $this->id_base);
|
||||
|
||||
echo $before_widget;
|
||||
|
||||
if ( $title )
|
||||
echo $before_title . $title . $after_title;
|
||||
$this->widget_start( $args, $instance );
|
||||
|
||||
get_product_search_form();
|
||||
|
||||
echo $after_widget;
|
||||
$this->widget_end( $args );
|
||||
}
|
||||
}
|
||||
|
|
|
@ -2,11 +2,11 @@
|
|||
/**
|
||||
* Tag Cloud Widget
|
||||
*
|
||||
* @author WooThemes
|
||||
* @category Widgets
|
||||
* @package WooCommerce/Widgets
|
||||
* @version 2.1.0
|
||||
* @extends WC_Widget
|
||||
* @author WooThemes
|
||||
* @category Widgets
|
||||
* @package WooCommerce/Widgets
|
||||
* @version 2.3.0
|
||||
* @extends WC_Widget
|
||||
*/
|
||||
|
||||
if ( ! defined( 'ABSPATH' ) ) {
|
||||
|
@ -30,6 +30,7 @@ class WC_Widget_Product_Tag_Cloud extends WC_Widget {
|
|||
'label' => __( 'Title', 'woocommerce' )
|
||||
)
|
||||
);
|
||||
|
||||
parent::__construct();
|
||||
}
|
||||
|
||||
|
@ -37,35 +38,29 @@ class WC_Widget_Product_Tag_Cloud extends WC_Widget {
|
|||
* widget function.
|
||||
*
|
||||
* @see WP_Widget
|
||||
* @access public
|
||||
*
|
||||
* @param array $args
|
||||
* @param array $instance
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function widget( $args, $instance ) {
|
||||
extract( $args );
|
||||
|
||||
$current_taxonomy = $this->_get_current_taxonomy($instance);
|
||||
$current_taxonomy = $this->_get_current_taxonomy( $instance );
|
||||
|
||||
if ( empty( $instance['title'] ) ) {
|
||||
$tax = get_taxonomy( $current_taxonomy );
|
||||
$title = apply_filters( 'widget_title', $tax->labels->name, $instance, $this->id_base );
|
||||
} else {
|
||||
$title = apply_filters( 'widget_title', $instance['title'], $instance, $this->id_base );
|
||||
$taxonomy = get_taxonomy( $current_taxonomy );
|
||||
$instance['title'] = $taxonomy->labels->name;
|
||||
}
|
||||
|
||||
echo $before_widget;
|
||||
|
||||
if ( $title )
|
||||
echo $before_title . $title . $after_title;
|
||||
$this->widget_start( $args, $instance );
|
||||
|
||||
echo '<div class="tagcloud">';
|
||||
|
||||
wp_tag_cloud( apply_filters( 'woocommerce_product_tag_cloud_widget_args', array( 'taxonomy' => $current_taxonomy ) ) );
|
||||
|
||||
echo "</div>";
|
||||
echo '</div>';
|
||||
|
||||
echo $after_widget;
|
||||
$this->widget_end( $args );
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -2,11 +2,11 @@
|
|||
/**
|
||||
* List products. One widget to rule them all.
|
||||
*
|
||||
* @author WooThemes
|
||||
* @category Widgets
|
||||
* @package WooCommerce/Widgets
|
||||
* @version 2.1.0
|
||||
* @extends WC_Widget
|
||||
* @author WooThemes
|
||||
* @category Widgets
|
||||
* @package WooCommerce/Widgets
|
||||
* @version 2.3.0
|
||||
* @extends WC_Widget
|
||||
*/
|
||||
|
||||
if ( ! defined( 'ABSPATH' ) ) {
|
||||
|
@ -78,6 +78,7 @@ class WC_Widget_Products extends WC_Widget {
|
|||
'label' => __( 'Show hidden products', 'woocommerce' )
|
||||
)
|
||||
);
|
||||
|
||||
parent::__construct();
|
||||
}
|
||||
|
||||
|
@ -88,61 +89,66 @@ class WC_Widget_Products extends WC_Widget {
|
|||
* @return WP_Query
|
||||
*/
|
||||
public function get_products( $args, $instance ) {
|
||||
$query_args = array(
|
||||
'posts_per_page' => absint( $instance['number'] ),
|
||||
$number = ! empty( $instance['number'] ) ? absint( $instance['number'] ) : $this->settings['number']['std'];
|
||||
$show = ! empty( $instance['show'] ) ? sanitize_title( $instance['show'] ) : $this->settings['show']['std'];
|
||||
$orderby = ! empty( $instance['orderby'] ) ? sanitize_title( $instance['orderby'] ) : $this->settings['orderby']['std'];
|
||||
$order = ! empty( $instance['order'] ) ? sanitize_title( $instance['order'] ) : $this->settings['order']['std'];
|
||||
|
||||
$query_args = array(
|
||||
'posts_per_page' => $number,
|
||||
'post_status' => 'publish',
|
||||
'post_type' => 'product',
|
||||
'no_found_rows' => 1,
|
||||
'order' => $instance['order'] === 'asc' ? 'asc' : 'desc',
|
||||
'order' => $order,
|
||||
'meta_query' => array()
|
||||
);
|
||||
);
|
||||
|
||||
if ( empty( $instance['show_hidden'] ) ) {
|
||||
if ( empty( $instance['show_hidden'] ) ) {
|
||||
$query_args['meta_query'][] = WC()->query->visibility_meta_query();
|
||||
$query_args['post_parent'] = 0;
|
||||
}
|
||||
|
||||
if ( ! empty( $instance['hide_free'] ) ) {
|
||||
$query_args['meta_query'][] = array(
|
||||
'key' => '_price',
|
||||
'value' => 0,
|
||||
'compare' => '>',
|
||||
'type' => 'DECIMAL',
|
||||
$query_args['meta_query'][] = array(
|
||||
'key' => '_price',
|
||||
'value' => 0,
|
||||
'compare' => '>',
|
||||
'type' => 'DECIMAL',
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
$query_args['meta_query'][] = WC()->query->stock_status_meta_query();
|
||||
$query_args['meta_query'] = array_filter( $query_args['meta_query'] );
|
||||
$query_args['meta_query'][] = WC()->query->stock_status_meta_query();
|
||||
$query_args['meta_query'] = array_filter( $query_args['meta_query'] );
|
||||
|
||||
switch ( $instance['show'] ) {
|
||||
case 'featured' :
|
||||
$query_args['meta_query'][] = array(
|
||||
switch ( $show ) {
|
||||
case 'featured' :
|
||||
$query_args['meta_query'][] = array(
|
||||
'key' => '_featured',
|
||||
'value' => 'yes'
|
||||
);
|
||||
break;
|
||||
case 'onsale' :
|
||||
break;
|
||||
case 'onsale' :
|
||||
$product_ids_on_sale = wc_get_product_ids_on_sale();
|
||||
$product_ids_on_sale[] = 0;
|
||||
$query_args['post__in'] = $product_ids_on_sale;
|
||||
break;
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
switch ( $instance['orderby'] ) {
|
||||
switch ( $orderby ) {
|
||||
case 'price' :
|
||||
$query_args['meta_key'] = '_price';
|
||||
$query_args['orderby'] = 'meta_value_num';
|
||||
$query_args['orderby'] = 'meta_value_num';
|
||||
break;
|
||||
case 'rand' :
|
||||
$query_args['orderby'] = 'rand';
|
||||
$query_args['orderby'] = 'rand';
|
||||
break;
|
||||
case 'sales' :
|
||||
$query_args['meta_key'] = 'total_sales';
|
||||
$query_args['orderby'] = 'meta_value_num';
|
||||
$query_args['orderby'] = 'meta_value_num';
|
||||
break;
|
||||
default :
|
||||
$query_args['orderby'] = 'date';
|
||||
}
|
||||
}
|
||||
|
||||
return new WP_Query( $query_args );
|
||||
}
|
||||
|
@ -175,7 +181,7 @@ class WC_Widget_Products extends WC_Widget {
|
|||
|
||||
echo '</ul>';
|
||||
|
||||
$this->widget_end( $args, $instance );
|
||||
$this->widget_end( $args );
|
||||
}
|
||||
|
||||
wp_reset_postdata();
|
||||
|
|
|
@ -2,11 +2,11 @@
|
|||
/**
|
||||
* Recent Reviews Widget
|
||||
*
|
||||
* @author WooThemes
|
||||
* @category Widgets
|
||||
* @package WooCommerce/Widgets
|
||||
* @version 2.1.0
|
||||
* @extends WC_Widget
|
||||
* @author WooThemes
|
||||
* @category Widgets
|
||||
* @package WooCommerce/Widgets
|
||||
* @version 2.3.0
|
||||
* @extends WC_Widget
|
||||
*/
|
||||
|
||||
if ( ! defined( 'ABSPATH' ) ) {
|
||||
|
@ -38,6 +38,7 @@ class WC_Widget_Recent_Reviews extends WC_Widget {
|
|||
'label' => __( 'Number of reviews to show', 'woocommerce' )
|
||||
)
|
||||
);
|
||||
|
||||
parent::__construct();
|
||||
}
|
||||
|
||||
|
@ -45,27 +46,27 @@ class WC_Widget_Recent_Reviews extends WC_Widget {
|
|||
* widget function.
|
||||
*
|
||||
* @see WP_Widget
|
||||
* @access public
|
||||
*
|
||||
* @param array $args
|
||||
* @param array $instance
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function widget( $args, $instance ) {
|
||||
global $comments, $comment;
|
||||
|
||||
if ( $this->get_cached_widget( $args ) )
|
||||
if ( $this->get_cached_widget( $args ) ) {
|
||||
return;
|
||||
}
|
||||
|
||||
ob_start();
|
||||
extract( $args );
|
||||
|
||||
$title = apply_filters( 'widget_title', $instance['title'], $instance, $this->id_base );
|
||||
$number = absint( $instance['number'] );
|
||||
$number = ! empty( $instance['number'] ) ? absint( $instance['number'] ) : $this->settings['number']['std'];
|
||||
$comments = get_comments( array( 'number' => $number, 'status' => 'approve', 'post_status' => 'publish', 'post_type' => 'product' ) );
|
||||
|
||||
if ( $comments ) {
|
||||
echo $before_widget;
|
||||
if ( $title ) echo $before_title . $title . $after_title;
|
||||
$this->widget_start( $args, $instance );
|
||||
|
||||
echo '<ul class="product_list_widget">';
|
||||
|
||||
foreach ( (array) $comments as $comment ) {
|
||||
|
@ -80,7 +81,7 @@ class WC_Widget_Recent_Reviews extends WC_Widget {
|
|||
|
||||
echo $_product->get_image();
|
||||
|
||||
echo $_product->get_title().'</a>';
|
||||
echo $_product->get_title() . '</a>';
|
||||
|
||||
echo $rating_html;
|
||||
|
||||
|
@ -90,7 +91,8 @@ class WC_Widget_Recent_Reviews extends WC_Widget {
|
|||
}
|
||||
|
||||
echo '</ul>';
|
||||
echo $after_widget;
|
||||
|
||||
$this->widget_end( $args );
|
||||
}
|
||||
|
||||
$content = ob_get_clean();
|
||||
|
|
|
@ -2,11 +2,11 @@
|
|||
/**
|
||||
* Recent Products Widget
|
||||
*
|
||||
* @author WooThemes
|
||||
* @category Widgets
|
||||
* @package WooCommerce/Widgets
|
||||
* @version 2.1.0
|
||||
* @extends WC_Widget
|
||||
* @author WooThemes
|
||||
* @category Widgets
|
||||
* @package WooCommerce/Widgets
|
||||
* @version 2.3.0
|
||||
* @extends WC_Widget
|
||||
*/
|
||||
|
||||
if ( ! defined( 'ABSPATH' ) ) {
|
||||
|
@ -38,6 +38,7 @@ class WC_Widget_Recently_Viewed extends WC_Widget {
|
|||
'label' => __( 'Number of products to show', 'woocommerce' )
|
||||
)
|
||||
);
|
||||
|
||||
parent::__construct();
|
||||
}
|
||||
|
||||
|
@ -45,50 +46,47 @@ class WC_Widget_Recently_Viewed extends WC_Widget {
|
|||
* widget function.
|
||||
*
|
||||
* @see WP_Widget
|
||||
* @access public
|
||||
*
|
||||
* @param array $args
|
||||
* @param array $instance
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
function widget($args, $instance) {
|
||||
function widget( $args, $instance ) {
|
||||
|
||||
$viewed_products = ! empty( $_COOKIE['woocommerce_recently_viewed'] ) ? (array) explode( '|', $_COOKIE['woocommerce_recently_viewed'] ) : array();
|
||||
$viewed_products = array_filter( array_map( 'absint', $viewed_products ) );
|
||||
|
||||
if ( empty( $viewed_products ) )
|
||||
if ( empty( $viewed_products ) ) {
|
||||
return;
|
||||
}
|
||||
|
||||
ob_start();
|
||||
extract( $args );
|
||||
|
||||
$title = apply_filters( 'widget_title', $instance['title'], $instance, $this->id_base );
|
||||
$number = absint( $instance['number'] );
|
||||
$number = ! empty( $instance['number'] ) ? absint( $instance['number'] ) : $this->settings['number']['std'];
|
||||
|
||||
$query_args = array( 'posts_per_page' => $number, 'no_found_rows' => 1, 'post_status' => 'publish', 'post_type' => 'product', 'post__in' => $viewed_products, 'orderby' => 'rand' );
|
||||
|
||||
$query_args['meta_query'] = array();
|
||||
$query_args['meta_query'] = array();
|
||||
$query_args['meta_query'][] = WC()->query->stock_status_meta_query();
|
||||
$query_args['meta_query'] = array_filter( $query_args['meta_query'] );
|
||||
$query_args['meta_query'] = array_filter( $query_args['meta_query'] );
|
||||
|
||||
$r = new WP_Query($query_args);
|
||||
$r = new WP_Query( $query_args );
|
||||
|
||||
if ( $r->have_posts() ) {
|
||||
|
||||
echo $before_widget;
|
||||
|
||||
if ( $title )
|
||||
echo $before_title . $title . $after_title;
|
||||
$this->widget_start( $args, $instance );
|
||||
|
||||
echo '<ul class="product_list_widget">';
|
||||
|
||||
while ( $r->have_posts()) {
|
||||
while ( $r->have_posts() ) {
|
||||
$r->the_post();
|
||||
wc_get_template( 'content-widget-product.php' );
|
||||
}
|
||||
|
||||
echo '</ul>';
|
||||
|
||||
echo $after_widget;
|
||||
$this->widget_end( $args );
|
||||
}
|
||||
|
||||
wp_reset_postdata();
|
||||
|
|
|
@ -4,11 +4,11 @@
|
|||
*
|
||||
* Gets and displays top rated products in an unordered list
|
||||
*
|
||||
* @author WooThemes
|
||||
* @category Widgets
|
||||
* @package WooCommerce/Widgets
|
||||
* @version 2.1.0
|
||||
* @extends WC_Widget
|
||||
* @author WooThemes
|
||||
* @category Widgets
|
||||
* @package WooCommerce/Widgets
|
||||
* @version 2.3.0
|
||||
* @extends WC_Widget
|
||||
*/
|
||||
|
||||
if ( ! defined( 'ABSPATH' ) ) {
|
||||
|
@ -40,6 +40,7 @@ class WC_Widget_Top_Rated_Products extends WC_Widget {
|
|||
'label' => __( 'Number of products to show', 'woocommerce' )
|
||||
)
|
||||
);
|
||||
|
||||
parent::__construct();
|
||||
}
|
||||
|
||||
|
@ -47,25 +48,25 @@ class WC_Widget_Top_Rated_Products extends WC_Widget {
|
|||
* widget function.
|
||||
*
|
||||
* @see WP_Widget
|
||||
* @access public
|
||||
*
|
||||
* @param array $args
|
||||
* @param array $instance
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function widget($args, $instance) {
|
||||
public function widget( $args, $instance ) {
|
||||
|
||||
if ( $this->get_cached_widget( $args ) )
|
||||
if ( $this->get_cached_widget( $args ) ) {
|
||||
return;
|
||||
}
|
||||
|
||||
ob_start();
|
||||
extract( $args );
|
||||
|
||||
$title = apply_filters( 'widget_title', $instance['title'], $instance, $this->id_base );
|
||||
$number = absint( $instance['number'] );
|
||||
$number = ! empty( $instance['number'] ) ? absint( $instance['number'] ) : $this->settings['number']['std'];
|
||||
|
||||
add_filter( 'posts_clauses', array( WC()->query, 'order_by_rating_post_clauses' ) );
|
||||
|
||||
$query_args = array('posts_per_page' => $number, 'no_found_rows' => 1, 'post_status' => 'publish', 'post_type' => 'product' );
|
||||
$query_args = array( 'posts_per_page' => $number, 'no_found_rows' => 1, 'post_status' => 'publish', 'post_type' => 'product' );
|
||||
|
||||
$query_args['meta_query'] = WC()->query->get_meta_query();
|
||||
|
||||
|
@ -73,10 +74,7 @@ class WC_Widget_Top_Rated_Products extends WC_Widget {
|
|||
|
||||
if ( $r->have_posts() ) {
|
||||
|
||||
echo $before_widget;
|
||||
|
||||
if ( $title )
|
||||
echo $before_title . $title . $after_title;
|
||||
$this->widget_start( $args, $instance );
|
||||
|
||||
echo '<ul class="product_list_widget">';
|
||||
|
||||
|
@ -87,7 +85,7 @@ class WC_Widget_Top_Rated_Products extends WC_Widget {
|
|||
|
||||
echo '</ul>';
|
||||
|
||||
echo $after_widget;
|
||||
$this->widget_end( $args );
|
||||
}
|
||||
|
||||
remove_filter( 'posts_clauses', array( WC()->query, 'order_by_rating_post_clauses' ) );
|
||||
|
|
Loading…
Reference in New Issue