'widget-recent',
'description' => __( "Your site’s most recent Posts.", 'mino' )
);
parent::__construct( 'recent-posts', __( 'Recent Posts', 'mino' ), $widget_ops );
$this->alt_option_name = 'widget_recent_entries';
}
/**
* Outputs the content for the custom Recent Posts
* @param array $args Argument for widgets
* @param array $instance Widget settings data
* @return -
*/
public function widget( $args, $instance ) {
if ( ! isset( $args['widget_id'] ) ) {
$args['widget_id'] = $this->id;
}
$title = ( ! empty( $instance['title'] ) ) ? $instance['title'] : __( 'Recent Posts', 'mino' );
/** This filter is documented in wp-includes/widgets/class-wp-widget-pages.php */
$title = apply_filters( 'widget_title', $title, $instance, $this->id_base );
$number = ( ! empty( $instance['number'] ) ) ? absint( $instance['number'] ) : 5;
if ( ! $number )
$number = 5;
$show_date = isset( $instance['show_date'] ) ? $instance['show_date'] : false;
$show_author = isset( $instance['show_author'] ) ? $instance['show_author'] : false;
$r = new WP_Query( apply_filters( 'widget_posts_args', array(
'posts_per_page' => $number,
'no_found_rows' => true,
'post_status' => 'publish',
'ignore_sticky_posts' => true
) ) );
if ( $r->have_posts() ) :
echo $args['before_widget'];
if ( $title ) {
echo $args['before_title'] . $title . $args['after_title'];
}
?>
have_posts() ) : $r->the_post(); ?>
-
id="get_field_id( 'show_date' ); ?>" name="get_field_name( 'show_date' ); ?>" />
id="get_field_id( 'show_author' ); ?>" name="get_field_name( 'show_author' ); ?>" />
post_count ) {
return;
}
$min_price = isset( $_GET['min_price'] ) ? esc_attr( $_GET['min_price'] ) : '';
$max_price = isset( $_GET['max_price'] ) ? esc_attr( $_GET['max_price'] ) : '';
wp_enqueue_script( 'wc-price-slider' );
// Remember current filters/search
$fields = '';
if ( get_search_query() ) {
$fields .= '';
}
if ( ! empty( $_GET['post_type'] ) ) {
$fields .= '';
}
if ( ! empty ( $_GET['product_cat'] ) ) {
$fields .= '';
}
if ( ! empty( $_GET['product_tag'] ) ) {
$fields .= '';
}
if ( ! empty( $_GET['orderby'] ) ) {
$fields .= '';
}
if ( ! empty( $_GET['min_rating'] ) ) {
$fields .= '';
}
if ( $_chosen_attributes = WC_Query::get_layered_nav_chosen_attributes() ) {
foreach ( $_chosen_attributes as $attribute => $data ) {
$taxonomy_filter = 'filter_' . str_replace( 'pa_', '', $attribute );
$fields .= '';
if ( 'or' == $data['query_type'] ) {
$fields .= '';
}
}
}
// Find min and max price in current result set
$prices = $this->get_filtered_price();
$min = floor( $prices->min_price );
$max = ceil( $prices->max_price );
if ( $min === $max ) {
return;
}
$this->widget_start( $args, $instance );
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( trailingslashit( $wp->request ) ) );
}
/**
* Adjust max if the store taxes are not displayed how they are stored.
* Min is left alone because the product may not be taxable.
* Kicks in when prices excluding tax are displayed including tax.
*/
if ( wc_tax_enabled() && 'incl' === get_option( 'woocommerce_tax_display_shop' ) && ! wc_prices_include_tax() ) {
$tax_classes = array_merge( array( '' ), WC_Tax::get_tax_classes() );
$class_max = $max;
foreach ( $tax_classes as $tax_class ) {
if ( $tax_rates = WC_Tax::get_rates( $tax_class ) ) {
$class_max = $max + WC_Tax::get_tax_total( WC_Tax::calc_exclusive_tax( $max, $tax_rates ) );
}
}
$max = $class_max;
}
echo '';
$this->widget_end( $args );
}
}
/**
* Register custom recent post widget
* @return -
*/
if ( ! function_exists( 'Mino_Register_Widget_Price_Filter' ) ) {
function Mino_Register_Widget_Price_Filter() {
register_widget( 'Mino_Widget_Price_Filter' );
}
}
add_action( 'widgets_init', 'Mino_Register_Widget_Price_Filter' );
class Mino_Widget_Layered_Nav extends WC_Widget_Layered_Nav {
/**
* Output widget.
*
* @see WP_Widget
*
* @param array $args
* @param array $instance
*/
public function widget( $args, $instance ) {
global $_chosen_attributes;
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 : '';
$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 ) ) {
return;
}
$get_terms_args = array( 'hide_empty' => '1' );
$orderby = wc_attribute_orderby( $taxonomy );
switch ( $orderby ) {
case 'name' :
$get_terms_args['orderby'] = 'name';
$get_terms_args['menu_order'] = false;
break;
case 'id' :
$get_terms_args['orderby'] = 'id';
$get_terms_args['order'] = 'ASC';
$get_terms_args['menu_order'] = false;
break;
case 'menu_order' :
$get_terms_args['menu_order'] = 'ASC';
break;
}
$terms = get_terms( $taxonomy, $get_terms_args );
if ( 0 < count( $terms ) ) {
ob_start();
$found = false;
$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 ) ) {
$found = true;
}
if ( 'dropdown' == $display_type ) {
// skip when viewing the taxonomy
if ( $current_tax && $taxonomy == $current_tax ) {
$found = false;
} else {
$taxonomy_filter = str_replace( 'pa_', '', $taxonomy );
$found = false;
echo '';
wc_enqueue_js( "
jQuery( '.dropdown_layered_nav_$taxonomy_filter' ).change( function() {
var term_id = parseInt( jQuery( this ).val(), 10 );
location.href = '" . preg_replace( '%\/page\/[0-9]+%', '', str_replace( array( '&', '%2C' ), array( '&', ',' ), esc_js( add_query_arg( 'filtering', '1', remove_query_arg( array( 'page', 'filter_' . $taxonomy_filter ) ) ) ) ) ) . "&filter_$taxonomy_filter=' + ( isNaN( term_id ) ? '' : term_id );
});
" );
}
} else {
// List display
echo '';
foreach ( $terms as $term ) {
// Get count based on current view - uses transients
$_products_in_term = wc_get_term_product_ids( $term->term_id, $taxonomy );
$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 ) {
continue;
}
// If this is an AND query, only show options with count > 0
if ( 'and' == $query_type ) {
$count = sizeof( array_intersect( $_products_in_term, WC()->query->filtered_product_ids ) );
if ( 0 < $count && $current_term !== $term->term_id ) {
$found = true;
}
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 ( 0 < $count ) {
$found = true;
}
}
$arg = 'filter_' . sanitize_title( $instance['attribute'] );
$current_filter = ( isset( $_GET[ $arg ] ) ) ? explode( ',', $_GET[ $arg ] ) : array();
if ( ! is_array( $current_filter ) ) {
$current_filter = array();
}
$current_filter = array_map( 'esc_attr', $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' ) ) {
$link = esc_url( home_url() );
} elseif ( is_post_type_archive( 'product' ) || is_page( wc_get_page_id('shop') ) ) {
$link = get_post_type_archive_link( 'product' );
} else {
$current_term = get_queried_object();
$link = get_term_link( $current_term->term_id, $current_term->taxonomy );
}
// All current filters
if ( $_chosen_attributes ) {
foreach ( $_chosen_attributes as $name => $data ) {
if ( $name !== $taxonomy ) {
// Exclude query arg for current term archive term
while ( in_array( $current_term, $data['terms'] ) ) {
$key = array_search( $current_term, $data );
unset( $data['terms'][$key] );
}
// Remove pa_ and sanitize
$filter_name = sanitize_title( str_replace( 'pa_', '', $name ) );
if ( ! empty( $data['terms'] ) ) {
$link = add_query_arg( 'filter_' . $filter_name, implode( ',', $data['terms'] ), $link );
}
if ( 'or' == $data['query_type'] ) {
$link = add_query_arg( 'query_type_' . $filter_name, 'or', $link );
}
}
}
}
// Min/Max
if ( isset( $_GET['min_price'] ) ) {
$link = add_query_arg( 'min_price', sanitize_text_field( $_GET['min_price'] ), $link );
}
if ( isset( $_GET['max_price'] ) ) {
$link = add_query_arg( 'max_price', sanitize_text_field( $_GET['max_price'] ), $link );
}
// Orderby
if ( isset( $_GET['orderby'] ) ) {
$link = add_query_arg( 'orderby', sanitize_text_field( $_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'] ) ) {
$class = 'class="chosen"';
// Remove this term is $current_filter has more than 1 term filtered
if ( sizeof( $current_filter ) > 1 ) {
$current_filter_without_this = array_diff( $current_filter, array( $term->term_id ) );
$link = add_query_arg( $arg, implode( ',', $current_filter_without_this ), $link );
}
} else {
$class = '';
$link = add_query_arg( $arg, implode( ',', $current_filter ), $link );
}
// Search Arg
if ( get_search_query() ) {
$link = add_query_arg( 's', get_search_query(), $link );
}
// Post Type Arg
if ( isset( $_GET['post_type'] ) ) {
$link = add_query_arg( 'post_type', sanitize_text_field( $_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'] ) ) ) {
$link = add_query_arg( 'query_type_' . sanitize_title( $instance['attribute'] ), 'or', $link );
}
echo '- ';
echo ( $count > 0 || $option_is_set ) ? '' : '';
echo $term->name;
echo ' ' . $count . '';
echo ( $count > 0 || $option_is_set ) ? '' : '';
echo '
';
}
echo '
';
} // End display type conditional
$this->widget_end( $args );
if ( ! $found ) {
ob_end_clean();
} else {
echo ob_get_clean();
}
}
}
}
/**
* Register custom recent post widget
* @return -
*/
if ( ! function_exists( 'Mino_Register_Widget_Layered_Nav' ) ) {
function Mino_Register_Widget_Layered_Nav() {
register_widget( 'Mino_Widget_Layered_Nav' );
}
}
add_action( 'widgets_init', 'Mino_Register_Widget_Layered_Nav' );
class Mino_Widget_Recent_Reviews extends WC_Widget_Recent_Reviews {
/**
* Output widget.
*
* @see WP_Widget
*
* @param array $args
* @param array $instance
*/
public function widget( $args, $instance ) {
global $comments, $comment;
if ( $this->get_cached_widget( $args ) ) {
return;
}
ob_start();
$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 ) {
$this->widget_start( $args, $instance );
echo '';
$this->widget_end( $args );
}
$content = ob_get_clean();
echo $content;
$this->cache_widget( $args, $content );
}
}
/**
* Register custom recent product reviews
* @return -
*/
if ( ! function_exists( 'Mino_Register_WC_Widget_Recent_Reviews' ) ) {
function Mino_Register_WC_Widget_Recent_Reviews() {
register_widget( 'Mino_Widget_Recent_Reviews' );
}
}
add_action( 'widgets_init', 'Mino_Register_WC_Widget_Recent_Reviews' );
}