esc_html__('A widget that shows woocommerce related category products.', 'buzzstore')
));
}
private function widget_fields() {
$taxonomy = 'product_cat';
$empty = 1;
$orderby = 'name';
$show_count = 0; // 1 for yes, 0 for no
$pad_counts = 0; // 1 for yes, 0 for no
$hierarchical = 1; // 1 for yes, 0 for no
$title = '';
$empty = 0;
$args = array(
'taxonomy' => $taxonomy,
'orderby' => $orderby,
'show_count' => $show_count,
'pad_counts' => $pad_counts,
'hierarchical' => $hierarchical,
'title_li' => $title,
'hide_empty' => $empty
);
$woocommerce_categories = array();
$woocommerce_categories_obj = get_categories($args);
foreach ($woocommerce_categories_obj as $category) {
$woocommerce_categories[$category->term_id] = $category->name;
}
$fields = array(
'buzzstore_product_title' => array(
'buzzstore_widgets_name' => 'buzzstore_product_title',
'buzzstore_widgets_title' => esc_html__('Title', 'buzzstore'),
'buzzstore_widgets_field_type' => 'title',
),
'buzzstore_product_short_desc' => array(
'buzzstore_widgets_name' => 'buzzstore_product_short_desc',
'buzzstore_widgets_title' => esc_html__('Short Description', 'buzzstore'),
'buzzstore_widgets_field_type' => 'text'
),
'buzzstore_category_product_type' => array(
'buzzstore_widgets_name' => 'buzzstore_category_product_type',
'buzzstore_mulicheckbox_title' => esc_html__('Select Product Categories', 'buzzstore'),
'buzzstore_widgets_field_type' => 'multicheckboxes',
'buzzstore_widgets_field_options' => $woocommerce_categories
),
'buzzstore_product_number' => array(
'buzzstore_widgets_name' => 'buzzstore_product_number',
'buzzstore_widgets_title' => esc_html__('Number of Products to Show', 'buzzstore'),
'buzzstore_widgets_field_type' => 'number',
),
);
return $fields;
}
public function widget($args, $instance) {
extract($args);
extract($instance);
/**
* wp query for first block
*/
$title = empty( $instance['buzzstore_product_title'] ) ? '' : $instance['buzzstore_product_title'];
$shot_desc = empty( $instance['buzzstore_product_short_desc'] ) ? '' : $instance['buzzstore_product_short_desc'];
$categories = empty( $instance['buzzstore_category_product_type'] ) ? '' : $instance['buzzstore_category_product_type'];
$product_number = intval( empty( $instance['buzzstore_product_number'] ) ? '' : $instance['buzzstore_product_number'] );
$product_args = '';
global $product_label_custom;
echo $before_widget;
?>
";
echo '
' . esc_html__('All', 'buzzstore') . '';
foreach ($categories as $key => $category) {
$term = get_term_by( 'id', $key, 'product_cat');
if(!$term) continue;
echo '
slug ) . '>' . esc_attr( $term->name ) . '';
}
echo "";
}
?>
$term_list) {
$term = get_term_by( 'id', $term_key, 'product_cat');
if(!$term) continue;
$term_id = $term->term_id;
$term_slug = $term->slug;
$product_args = array(
'post_type' => 'product',
'tax_query' => array(
array(
'taxonomy' => 'product_cat',
'field' => 'id',
'terms' => $term_id
)),
'posts_per_page' => $product_number
);
$query = new WP_Query($product_args);
if($query->have_posts()) { while($query->have_posts()) { $query->the_post();
$buzzterms = wp_get_post_terms(get_the_ID(),'product_cat', array("fields" => "all"));
$term_slugs = array();
foreach ($buzzterms as $buzzterm) {
$term_slugs[] = $buzzterm->slug;
}
$term_slugs = join(' ', $term_slugs);
?>
widget_fields();
foreach ($widget_fields as $widget_field) {
extract($widget_field);
$instance[$buzzstore_widgets_name] = buzzstore_widgets_updated_field_value($widget_field, $new_instance[$buzzstore_widgets_name]);
}
return $instance;
}
public function form($instance) {
$widget_fields = $this->widget_fields();
foreach ($widget_fields as $widget_field) {
extract($widget_field);
$buzzstore_widgets_field_value = !empty($instance[$buzzstore_widgets_name]) ? $instance[$buzzstore_widgets_name] : '';
buzzstore_widgets_show_widget_field($this, $widget_field, $buzzstore_widgets_field_value);
}
}
}
/**
* Adds buzzstore_product_widget widget.
*/
add_action('widgets_init', 'buzzstore_product_widget');
function buzzstore_product_widget() {
register_widget('buzzstore_product_widget_area');
}
class buzzstore_product_widget_area extends WP_Widget {
/**
* Register widget with WordPress.
**/
public function __construct() {
parent::__construct(
'buzzstore_product_widget_area', esc_html__(' Buzz: Woo Product Area','buzzstore'), array(
'description' => esc_html__('A widget that shows woocommerce all type product (Latest, Feature, On Sale, Up Sale) and selected category products', 'buzzstore')
));
}
private function widget_fields() {
$prod_type = array(
'category' => esc_html__('Category', 'buzzstore'),
'latest_product' => esc_html__('Latest Product', 'buzzstore'),
'upsell_product' => esc_html__('UpSell Product', 'buzzstore'),
'feature_product' => esc_html__('Feature Product', 'buzzstore'),
'on_sale' => esc_html__('On Sale Product', 'buzzstore'),
);
$taxonomy = 'product_cat';
$empty = 1;
$orderby = 'name';
$show_count = 0; // 1 for yes, 0 for no
$pad_counts = 0; // 1 for yes, 0 for no
$hierarchical = 1; // 1 for yes, 0 for no
$title = '';
$empty = 0;
$args = array(
'taxonomy' => $taxonomy,
'orderby' => $orderby,
'show_count' => $show_count,
'pad_counts' => $pad_counts,
'hierarchical' => $hierarchical,
'title_li' => $title,
'hide_empty' => $empty
);
$woocommerce_categories = array();
$woocommerce_categories_obj = get_categories($args);
$woocommerce_categories[''] = esc_html__('Select Category','buzzstore');
foreach ($woocommerce_categories_obj as $category) {
$woocommerce_categories[$category->term_id] = $category->name;
}
$fields = array(
'buzzstore_product_title' => array(
'buzzstore_widgets_name' => 'buzzstore_product_title',
'buzzstore_widgets_title' => esc_html__('Title', 'buzzstore'),
'buzzstore_widgets_field_type' => 'title',
),
'buzzstore_product_short_desc' => array(
'buzzstore_widgets_name' => 'buzzstore_product_short_desc',
'buzzstore_widgets_title' => esc_html__('Short Description', 'buzzstore'),
'buzzstore_widgets_field_type' => 'text'
),
'buzzstore_product_type' => array(
'buzzstore_widgets_name' => 'buzzstore_product_type',
'buzzstore_widgets_title' => esc_html__('Product Type', 'buzzstore'),
'buzzstore_widgets_field_type' => 'select',
'buzzstore_widgets_field_options' => $prod_type
),
'buzzstore_woo_category' => array(
'buzzstore_widgets_name' => 'buzzstore_woo_category',
'buzzstore_widgets_title' => esc_html__('Select Category', 'buzzstore'),
'buzzstore_widgets_field_type' => 'select',
'buzzstore_widgets_field_options' => $woocommerce_categories
),
'buzzstore_product_number' => array(
'buzzstore_widgets_name' => 'buzzstore_product_number',
'buzzstore_widgets_title' => esc_html__('Number of Products', 'buzzstore'),
'buzzstore_widgets_field_type' => 'number',
),
'buzzstore_product_cols_no' => array(
'buzzstore_widgets_name' => 'buzzstore_product_cols_no',
'buzzstore_widgets_title' => esc_html__('Number of Columns', 'buzzstore'),
'buzzstore_widgets_field_type' => 'select',
'buzzstore_widgets_field_options' => array(
'1' => esc_html__('1', 'buzzstore'),
'2' => esc_html__('2', 'buzzstore'),
'3' => esc_html__('3', 'buzzstore'),
'4' => esc_html__('4', 'buzzstore'),
),
),
);
return $fields;
}
public function widget($args, $instance) {
extract($args);
extract($instance);
/**
* wp query for first block
*/
$title = empty( $instance['buzzstore_product_title'] ) ? '' : $instance['buzzstore_product_title'];
$shot_desc = empty( $instance['buzzstore_product_short_desc'] ) ? '' : $instance['buzzstore_product_short_desc'];
$product_type = empty( $instance['buzzstore_product_type'] ) ? '' : $instance['buzzstore_product_type'];
$product_category = intval( empty( $instance['buzzstore_woo_category'] ) ? '' : $instance['buzzstore_woo_category'] );
$product_number = intval( empty( $instance['buzzstore_product_number'] ) ? '' : $instance['buzzstore_product_number'] );
$product_cols_no = empty( $instance['buzzstore_product_cols_no'] ) ? '' : $instance['buzzstore_product_cols_no'];
$product_args = '';
global $product_label_custom;
if($product_type == 'category'){
$product_args = array(
'post_type' => 'product',
'tax_query' => array(
array('taxonomy' => 'product_cat',
'field' => 'id',
'terms' => $product_category
)
),
'posts_per_page' => $product_number
);
}
elseif($product_type == 'latest_product'){
$product_label_custom = esc_html__('New', 'buzzstore');
$product_args = array(
'post_type' => 'product',
'tax_query' => array(
array('taxonomy' => 'product_cat',
'field' => 'id',
'terms' => $product_category
)
),
'posts_per_page' => $product_number
);
}
elseif($product_type == 'upsell_product'){
$product_args = array(
'post_type' => 'product',
'posts_per_page' => 10,
'meta_key' => 'total_sales',
'orderby' => 'meta_value_num',
'posts_per_page' => $product_number
);
}
elseif($product_type == 'feature_product'){
$product_args = array(
'post_type' => 'product',
'tax_query' => array(
'relation' => 'AND',
array(
'taxonomy' => 'product_visibility',
'field' => 'name',
'terms' => 'featured',
'operator' => 'IN'
),
array(
'taxonomy' => 'product_cat',
'field' => 'term_id',
'terms' => $product_category
)
),
'posts_per_page' => $product_number
);
}
elseif($product_type == 'on_sale'){
$product_args = array(
'post_type' => 'product',
'posts_per_page' => $product_number,
'meta_query' => array(
'relation' => 'OR',
array( // Simple products type
'key' => '_sale_price',
'value' => 0,
'compare' => '>',
'type' => 'numeric'
),
array( // Variable products type
'key' => '_min_variation_sale_price',
'value' => 0,
'compare' => '>',
'type' => 'numeric'
)
));
}
echo $before_widget;
?>
have_posts()) { while($query->have_posts()) { $query->the_post();
?>
widget_fields();
foreach ($widget_fields as $widget_field) {
extract($widget_field);
$instance[$buzzstore_widgets_name] = buzzstore_widgets_updated_field_value($widget_field, $new_instance[$buzzstore_widgets_name]);
}
return $instance;
}
public function form($instance) {
$widget_fields = $this->widget_fields();
foreach ($widget_fields as $widget_field) {
extract($widget_field);
$buzzstore_widgets_field_value = !empty($instance[$buzzstore_widgets_name]) ? $instance[$buzzstore_widgets_name] : '';
buzzstore_widgets_show_widget_field($this, $widget_field, $buzzstore_widgets_field_value);
}
}
}
/**
* Adds buzzstore_cat_widget widget.
*/
add_action('widgets_init', 'buzzstore_cat_widget');
function buzzstore_cat_widget() {
register_widget('buzzstore_cat_widget_area');
}
class buzzstore_cat_widget_area extends WP_Widget {
/**
* Register widget with WordPress.
*/
public function __construct() {
parent::__construct(
'buzzstore_cat_widget_area', esc_html__(' Buzz: Woo Category Collection','buzzstore'), array(
'description' => esc_html__('A widget that shows woocommerce category', 'buzzstore')
));
}
private function widget_fields() {
$taxonomy = 'product_cat';
$empty = 1;
$orderby = 'name';
$show_count = 0; // 1 for yes, 0 for no
$pad_counts = 0; // 1 for yes, 0 for no
$hierarchical = 1; // 1 for yes, 0 for no
$title = '';
$empty = 0;
$args = array(
'taxonomy' => $taxonomy,
'orderby' => $orderby,
'show_count' => $show_count,
'pad_counts' => $pad_counts,
'hierarchical' => $hierarchical,
'title_li' => $title,
'hide_empty' => $empty
);
$woocommerce_categories = array();
$woocommerce_categories_obj = get_categories($args);
foreach ($woocommerce_categories_obj as $category) {
$woocommerce_categories[$category->term_id] = $category->name;
}
$fields = array(
'buzzstore_main_cat_title' => array(
'buzzstore_widgets_name' => 'buzzstore_main_cat_title',
'buzzstore_widgets_title' => esc_html__('Title', 'buzzstore'),
'buzzstore_widgets_field_type' => 'title',
),
'buzzstore_cat_short_desc' => array(
'buzzstore_widgets_name' => 'buzzstore_cat_short_desc',
'buzzstore_widgets_title' => esc_html__('Short Description', 'buzzstore'),
'buzzstore_widgets_field_type' => 'text'
),
'buzzstore_select_category' => array(
'buzzstore_widgets_name' => 'buzzstore_select_category',
'buzzstore_mulicheckbox_title' => esc_html__('Select Categories', 'buzzstore'),
'buzzstore_widgets_field_type' => 'multicheckboxes',
'buzzstore_widgets_field_options' => $woocommerce_categories
),
'buzzstore_cat_coll_columns_no' => array(
'buzzstore_widgets_name' => 'buzzstore_cat_coll_columns_no',
'buzzstore_widgets_title' => esc_html__('Number of Columns', 'buzzstore'),
'buzzstore_widgets_field_type' => 'select',
'buzzstore_widgets_field_options' => array(
'1' => __('1', 'buzzstore'),
'2' => __('2', 'buzzstore'),
'3' => __('3', 'buzzstore'),
'4' => __('4', 'buzzstore'),
),
),
);
return $fields;
}
public function widget($args, $instance) {
extract($args);
extract($instance);
/**
* wp query for first block
*/
$title = empty( $instance['buzzstore_main_cat_title'] ) ? '' : $instance['buzzstore_main_cat_title'];
$shot_desc = empty( $instance['buzzstore_cat_short_desc'] ) ? '' : $instance['buzzstore_cat_short_desc'];
$buzzstore_cat_coll_columns_no = empty( $instance['buzzstore_cat_coll_columns_no'] ) ? '' : $instance['buzzstore_cat_coll_columns_no'];
$buzz_store_cat_id = empty( $instance['buzzstore_select_category'] ) ? '' : $instance['buzzstore_select_category'];
echo $before_widget;
?>
$store_cat_id) {
$thumbnail_id = get_term_meta( $key, 'thumbnail_id', true );
$images = wp_get_attachment_url( $thumbnail_id );
$image = wp_get_attachment_image_src($thumbnail_id, 'buzzstore-cat-image', true);
$term = get_term_by( 'id', $key, 'product_cat');
if ( $term && ! is_wp_error( $term ) ) {
$term_link = get_term_link($term);
$term_name = $term->name;
if ( $term->count > 0 )
$sub_count = apply_filters( 'woocommerce_subcategory_count_html', ' ' . $term->count . ' '.esc_html__('Products','buzzstore').'', $term);
}else{
$term_link = '#';
$term_name = esc_html__('Category','buzzstore');
$sub_count = '0 '.esc_html__('Product','buzzstore');
}
$no_img = esc_url( get_template_directory_uri().'/assets/images/noimage.png' );
?>
widget_fields();
foreach ($widget_fields as $widget_field) {
extract($widget_field);
$instance[$buzzstore_widgets_name] = buzzstore_widgets_updated_field_value($widget_field, $new_instance[$buzzstore_widgets_name]);
}
return $instance;
}
public function form($instance) {
$widget_fields = $this->widget_fields();
foreach ($widget_fields as $widget_field) {
extract($widget_field);
$buzzstore_widgets_field_value = !empty($instance[$buzzstore_widgets_name]) ? $instance[$buzzstore_widgets_name] : '';
buzzstore_widgets_show_widget_field($this, $widget_field, $buzzstore_widgets_field_value);
}
}
}
}