Perfect Brands for WooCommerce - Version 1.7.3

Version Description

  • Enhancement: Performance improvements
  • Fix: Breadcrumbs doesn't take in account pagination
Download this release

Release Info

Developer titodevera
Plugin Icon 128x128 Perfect Brands for WooCommerce
Version 1.7.3
Comparing to
See all releases

Code changes from version 1.7.2 to 1.7.3

classes/class-perfect-woocommerce-brands.php CHANGED
@@ -41,7 +41,7 @@ class Perfect_Woocommerce_Brands{
41
  }
42
 
43
  public function brand_name_in_url( $permalink, $post ){
44
- if( $post->post_type == 'product' ) {
45
  $term = 'product';
46
  $brands = wp_get_post_terms( $post->ID, 'pwb-brand' );
47
  if( ! empty( $brands ) && ! is_wp_error( $brands ) ) $term = current( $brands )->slug;
@@ -188,22 +188,7 @@ class Perfect_Woocommerce_Brands{
188
  }
189
 
190
  /*
191
- * Adds microdata (brands) to single products (WooCommerce < 3.0.0)
192
- */
193
- public function product_microdata_legacy(){
194
- global $post;
195
-
196
- if( isset( $post->post_type ) && $post->post_type==='product' ){
197
- $brands = wp_get_post_terms( $post->ID, 'pwb-brand');
198
- foreach ($brands as $brand) {
199
- echo '<meta itemprop="brand" content="'.$brand->name.'">';
200
- }
201
- }
202
-
203
- }
204
-
205
- /*
206
- * Adds microdata (brands) to single products (WooCommerce > 3.0.0)
207
  */
208
  public function product_microdata( $markup, $product ){
209
 
@@ -870,11 +855,16 @@ class Perfect_Woocommerce_Brands{
870
  }
871
 
872
  public function breadcrumbs( $crumbs ) {
 
873
  if( is_tax('pwb-brand') ){
874
  $brands_page_id = get_option('wc_pwb_admin_tab_brands_page_id');
 
875
  if( !empty( $brands_page_id ) && $brands_page_id != '-' && isset( $crumbs[count($crumbs)-2][1] ) ){
876
- $crumbs[count($crumbs)-2][1] = get_page_link( $brands_page_id );
 
 
877
  }
 
878
  }
879
  return $crumbs;
880
  }
41
  }
42
 
43
  public function brand_name_in_url( $permalink, $post ){
44
+ if( $post->post_type == 'product' && strpos( $permalink, '%pwb-brand%' ) !== false ) {
45
  $term = 'product';
46
  $brands = wp_get_post_terms( $post->ID, 'pwb-brand' );
47
  if( ! empty( $brands ) && ! is_wp_error( $brands ) ) $term = current( $brands )->slug;
188
  }
189
 
190
  /*
191
+ * Adds microdata (brands) to single products
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
192
  */
193
  public function product_microdata( $markup, $product ){
194
 
855
  }
856
 
857
  public function breadcrumbs( $crumbs ) {
858
+
859
  if( is_tax('pwb-brand') ){
860
  $brands_page_id = get_option('wc_pwb_admin_tab_brands_page_id');
861
+
862
  if( !empty( $brands_page_id ) && $brands_page_id != '-' && isset( $crumbs[count($crumbs)-2][1] ) ){
863
+ $crumb_index = ( is_paged() ) ? count($crumbs)-3 : count($crumbs)-2;
864
+ if( isset( $crumb_index ) )
865
+ $crumbs[$crumb_index][1] = get_page_link( $brands_page_id );
866
  }
867
+
868
  }
869
  return $crumbs;
870
  }
classes/widgets/class-pwb-filter-by-brand.php CHANGED
@@ -88,16 +88,11 @@ class PWB_Filter_By_Brand_Widget extends \WP_Widget {
88
 
89
  public function render_widget( $current_products, $limit, $hide_submit_btn ){
90
 
 
 
91
  if( is_product_category() || is_shop() ){
92
 
93
- if( !empty( $current_products ) ) {
94
- $result_brands = array();
95
- foreach( $current_products as $product_id ) {
96
- $product_brands = wp_get_post_terms($product_id, 'pwb-brand');
97
- foreach($product_brands as $brand) $result_brands[] = $brand->term_id;
98
- }
99
- $result_brands = array_unique($result_brands);
100
- }
101
 
102
  if( is_shop() ){
103
  $cate_url = get_permalink( wc_get_page_id( 'shop' ) );
@@ -181,4 +176,24 @@ class PWB_Filter_By_Brand_Widget extends \WP_Widget {
181
 
182
  }
183
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
184
  }
88
 
89
  public function render_widget( $current_products, $limit, $hide_submit_btn ){
90
 
91
+ $result_brands = array();
92
+
93
  if( is_product_category() || is_shop() ){
94
 
95
+ if( !empty( $current_products ) ) $result_brands = $this->get_products_brands( $current_products );
 
 
 
 
 
 
 
96
 
97
  if( is_shop() ){
98
  $cate_url = get_permalink( wc_get_page_id( 'shop' ) );
176
 
177
  }
178
 
179
+ private function get_products_brands( $product_ids ){
180
+
181
+ $product_ids = implode(',', array_map('intval', $product_ids) );
182
+
183
+ global $wpdb;
184
+ $brand_ids = $wpdb->get_col( "SELECT DISTINCT t.term_id
185
+ FROM {$wpdb->prefix}terms AS t
186
+ INNER JOIN {$wpdb->prefix}term_taxonomy AS tt
187
+ ON t.term_id = tt.term_id
188
+ INNER JOIN {$wpdb->prefix}term_relationships AS tr
189
+ ON tr.term_taxonomy_id = tt.term_taxonomy_id
190
+ WHERE tt.taxonomy IN ('pwb-brand')
191
+ AND tr.object_id IN ($product_ids)
192
+ ORDER BY t.name ASC
193
+ " );
194
+
195
+ return ( $brand_ids ) ? $brand_ids : false;
196
+
197
+ }
198
+
199
  }
main.php CHANGED
@@ -3,13 +3,13 @@
3
  * Plugin Name: Perfect WooCommerce Brands
4
  * Plugin URI: https://wordpress.org/plugins/perfect-woocommerce-brands/
5
  * Description: Perfect WooCommerce Brands allows you to show product brands in your WooCommerce based store.
6
- * Version: 1.7.2
7
  * Author: Alberto de Vera Sevilla
8
  * Author URI: https://profiles.wordpress.org/titodevera/
9
  * Text Domain: perfect-woocommerce-brands
10
  * Domain Path: /lang
11
  * License: GPL3
12
- * Perfect WooCommerce Brands version 1.7.2, Copyright (C) 2019 Alberto de Vera Sevilla
13
  * Perfect WooCommerce Brands is free software: you can redistribute it and/or modify
14
  * it under the terms of the GNU General Public License as published by
15
  * the Free Software Foundation, either version 3 of the License, or
@@ -34,7 +34,7 @@ defined( 'ABSPATH' ) or die( 'No script kiddies please!' );
34
  define( 'PWB_PLUGIN', plugins_url( '', __FILE__ ) );
35
  define( 'PWB_PLUGIN_PATH', plugin_basename( dirname( __FILE__ ) ) );
36
  define( 'PWB_PLUGIN_BASENAME', plugin_basename( __FILE__ ) );
37
- define( 'PWB_PLUGIN_VERSION', '1.7.2' );
38
  define( 'PWB_WP_VERSION', get_bloginfo( 'version' ) );
39
  define( 'PWB_WC_VERSION', get_option( 'woocommerce_version' ) );
40
 
3
  * Plugin Name: Perfect WooCommerce Brands
4
  * Plugin URI: https://wordpress.org/plugins/perfect-woocommerce-brands/
5
  * Description: Perfect WooCommerce Brands allows you to show product brands in your WooCommerce based store.
6
+ * Version: 1.7.3
7
  * Author: Alberto de Vera Sevilla
8
  * Author URI: https://profiles.wordpress.org/titodevera/
9
  * Text Domain: perfect-woocommerce-brands
10
  * Domain Path: /lang
11
  * License: GPL3
12
+ * Perfect WooCommerce Brands version 1.7.3, Copyright (C) 2019 Alberto de Vera Sevilla
13
  * Perfect WooCommerce Brands is free software: you can redistribute it and/or modify
14
  * it under the terms of the GNU General Public License as published by
15
  * the Free Software Foundation, either version 3 of the License, or
34
  define( 'PWB_PLUGIN', plugins_url( '', __FILE__ ) );
35
  define( 'PWB_PLUGIN_PATH', plugin_basename( dirname( __FILE__ ) ) );
36
  define( 'PWB_PLUGIN_BASENAME', plugin_basename( __FILE__ ) );
37
+ define( 'PWB_PLUGIN_VERSION', '1.7.3' );
38
  define( 'PWB_WP_VERSION', get_bloginfo( 'version' ) );
39
  define( 'PWB_WC_VERSION', get_option( 'woocommerce_version' ) );
40
 
readme.txt CHANGED
@@ -5,7 +5,7 @@ Tags: woocommerce, brands, brand taxonomy, product brands, woocommerce manufactu
5
  Requires at least: 4.7
6
  Tested up to: 5.1
7
  Requires PHP: 5.6
8
- Stable tag: 1.7.2
9
  License: GPL3
10
  License URI: http://www.gnu.org/licenses/gpl-3.0.en.html
11
 
@@ -81,6 +81,9 @@ You can also contribute [translating the plugin](https://translate.wordpress.org
81
 
82
 
83
  == Changelog ==
 
 
 
84
  = 1.7.2 =
85
  * Feature: Now is possible to use %pwb-brand% in the product URLs
86
  * Fix: Fatal error in some themes (like Salient)
5
  Requires at least: 4.7
6
  Tested up to: 5.1
7
  Requires PHP: 5.6
8
+ Stable tag: 1.7.3
9
  License: GPL3
10
  License URI: http://www.gnu.org/licenses/gpl-3.0.en.html
11
 
81
 
82
 
83
  == Changelog ==
84
+ = 1.7.3 =
85
+ * Enhancement: Performance improvements
86
+ * Fix: Breadcrumbs doesn't take in account pagination
87
  = 1.7.2 =
88
  * Feature: Now is possible to use %pwb-brand% in the product URLs
89
  * Fix: Fatal error in some themes (like Salient)