Facebook for WooCommerce - Version 2.3.3

Version Description

Download this release

Release Info

Developer automattic
Plugin Icon Facebook for WooCommerce
Version 2.3.3
Comparing to
See all releases

Code changes from version 2.3.2 to 2.3.3

changelog.txt CHANGED
@@ -1,5 +1,11 @@
1
  *** Facebook for WooCommerce Changelog ***
2
 
 
 
 
 
 
 
3
  2021.03.02 - version 2.3.2
4
  * Tweak - Bump Facebook Marketing API version to 9.0
5
 
@@ -12,7 +18,7 @@
12
  * Feature - Add support for Facebook App store flow
13
  * Tweak - Ask merchants to delete products when changing from sync to not sync state
14
  * Tweak - Remove business_management permission from login scopes
15
- * Tweak - Store paramaters for Commerce merchant settings ID and Instagram business ID
16
  * Fix - Fix Products::get_google_product_category_id_from_highest_category() to handle WP_Error
17
  * Fix - Fix random HELLO appearing in the category settings
18
  * Fix - Make sure that list of strings params are now converted to actual arrays. Fixes an issue with the use of the additional_features parameter
1
  *** Facebook for WooCommerce Changelog ***
2
 
3
+ 2021.03.22 - version 2.3.3
4
+ * Fix - WooCommerce variation attribute sync not matching Enhanced Catalog attributes.
5
+ * Fix - Enable display names to be used for variant attribute values.
6
+ * Fix - Performance, do not auto-load Google Categories option.
7
+ * Fix - Logs being recorded even with debug option disabled.
8
+
9
  2021.03.02 - version 2.3.2
10
  * Tweak - Bump Facebook Marketing API version to 9.0
11
 
18
  * Feature - Add support for Facebook App store flow
19
  * Tweak - Ask merchants to delete products when changing from sync to not sync state
20
  * Tweak - Remove business_management permission from login scopes
21
+ * Tweak - Store parameters for Commerce merchant settings ID and Instagram business ID
22
  * Fix - Fix Products::get_google_product_category_id_from_highest_category() to handle WP_Error
23
  * Fix - Fix random HELLO appearing in the category settings
24
  * Fix - Make sure that list of strings params are now converted to actual arrays. Fixes an issue with the use of the additional_features parameter
class-wc-facebookcommerce.php CHANGED
@@ -22,7 +22,7 @@ if ( ! class_exists( 'WC_Facebookcommerce' ) ) :
22
 
23
 
24
  /** @var string the plugin version */
25
- const VERSION = '2.3.2';
26
 
27
  /** @var string for backwards compatibility TODO: remove this in v2.0.0 {CW 2020-02-06} */
28
  const PLUGIN_VERSION = self::VERSION;
@@ -368,6 +368,21 @@ if ( ! class_exists( 'WC_Facebookcommerce' ) ) :
368
  new WP_Facebook_Integration();
369
  }
370
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
371
 
372
  /**
373
  * Logs an API request.
22
 
23
 
24
  /** @var string the plugin version */
25
+ const VERSION = '2.3.3';
26
 
27
  /** @var string for backwards compatibility TODO: remove this in v2.0.0 {CW 2020-02-06} */
28
  const PLUGIN_VERSION = self::VERSION;
368
  new WP_Facebook_Integration();
369
  }
370
 
371
+ /**
372
+ * Saves errors or messages to WooCommerce Log (woocommerce/logs/plugin-id-xxx.txt)
373
+ *
374
+ * @since 2.3.3
375
+ * @param string $message error or message to save to log
376
+ * @param string $log_id optional log id to segment the files by, defaults to plugin id
377
+ */
378
+ public function log( $message, $log_id = null ) {
379
+ // bail if logging isn't enabled
380
+ if ( ! $this->get_integration() || ! $this->get_integration()->is_debug_mode_enabled() ) {
381
+ return;
382
+ }
383
+
384
+ parent::log( $message, $log_id );
385
+ }
386
 
387
  /**
388
  * Logs an API request.
facebook-for-woocommerce.php CHANGED
@@ -10,10 +10,10 @@
10
  * Description: Grow your business on Facebook! Use this official plugin to help sell more of your products using Facebook. After completing the setup, you'll be ready to create ads that promote your products and you can also create a shop section on your Page where customers can browse your products on Facebook.
11
  * Author: Facebook
12
  * Author URI: https://www.facebook.com/
13
- * Version: 2.3.2
14
  * Text Domain: facebook-for-woocommerce
15
  * WC requires at least: 3.5.0
16
- * WC tested up to: 5.0.0
17
  *
18
  * @package FacebookCommerce
19
  */
10
  * Description: Grow your business on Facebook! Use this official plugin to help sell more of your products using Facebook. After completing the setup, you'll be ready to create ads that promote your products and you can also create a shop section on your Page where customers can browse your products on Facebook.
11
  * Author: Facebook
12
  * Author URI: https://www.facebook.com/
13
+ * Version: 2.3.3
14
  * Text Domain: facebook-for-woocommerce
15
  * WC requires at least: 3.5.0
16
+ * WC tested up to: 5.1.0
17
  *
18
  * @package FacebookCommerce
19
  */
i18n/languages/facebook-for-woocommerce.pot CHANGED
@@ -2,10 +2,10 @@
2
  # This file is distributed under the same license as the Facebook for WooCommerce package.
3
  msgid ""
4
  msgstr ""
5
- "Project-Id-Version: Facebook for WooCommerce 2.3.2\n"
6
  "Report-Msgid-Bugs-To: "
7
  "https://woocommerce.com/my-account/marketplace-ticket-form/\n"
8
- "POT-Creation-Date: 2021-03-01 23:05:59+00:00\n"
9
  "MIME-Version: 1.0\n"
10
  "Content-Type: text/plain; charset=utf-8\n"
11
  "Content-Transfer-Encoding: 8bit\n"
@@ -61,45 +61,45 @@ msgstr ""
61
  msgid "Heads up! The Facebook menu is now located under the %1$sMarketing%2$s menu."
62
  msgstr ""
63
 
64
- #: class-wc-facebookcommerce.php:407
65
  msgid "FB Product Sets"
66
  msgstr ""
67
 
68
- #: class-wc-facebookcommerce.php:408
69
  msgid "FB Product Set"
70
  msgstr ""
71
 
72
- #: class-wc-facebookcommerce.php:416
73
  #. translators: Edit item label
74
  msgid "Edit %s"
75
  msgstr ""
76
 
77
- #: class-wc-facebookcommerce.php:418
78
  #. translators: Add new label
79
  msgid "Add new %s"
80
  msgstr ""
81
 
82
- #: class-wc-facebookcommerce.php:421
83
  #. translators: No items found text
84
  msgid "No %s found."
85
  msgstr ""
86
 
87
- #: class-wc-facebookcommerce.php:423
88
  #. translators: Search label
89
  msgid "Search %s."
90
  msgstr ""
91
 
92
- #: class-wc-facebookcommerce.php:425
93
  #. translators: Text label
94
  msgid "Separate %s with commas"
95
  msgstr ""
96
 
97
- #: class-wc-facebookcommerce.php:427
98
  #. translators: Text label
99
  msgid "Choose from the most used %s"
100
  msgstr ""
101
 
102
- #: class-wc-facebookcommerce.php:543
103
  msgid "Cannot create the API instance because the access token is missing."
104
  msgstr ""
105
 
2
  # This file is distributed under the same license as the Facebook for WooCommerce package.
3
  msgid ""
4
  msgstr ""
5
+ "Project-Id-Version: Facebook for WooCommerce 2.3.3\n"
6
  "Report-Msgid-Bugs-To: "
7
  "https://woocommerce.com/my-account/marketplace-ticket-form/\n"
8
+ "POT-Creation-Date: 2021-03-22 09:51:42+00:00\n"
9
  "MIME-Version: 1.0\n"
10
  "Content-Type: text/plain; charset=utf-8\n"
11
  "Content-Transfer-Encoding: 8bit\n"
61
  msgid "Heads up! The Facebook menu is now located under the %1$sMarketing%2$s menu."
62
  msgstr ""
63
 
64
+ #: class-wc-facebookcommerce.php:422
65
  msgid "FB Product Sets"
66
  msgstr ""
67
 
68
+ #: class-wc-facebookcommerce.php:423
69
  msgid "FB Product Set"
70
  msgstr ""
71
 
72
+ #: class-wc-facebookcommerce.php:431
73
  #. translators: Edit item label
74
  msgid "Edit %s"
75
  msgstr ""
76
 
77
+ #: class-wc-facebookcommerce.php:433
78
  #. translators: Add new label
79
  msgid "Add new %s"
80
  msgstr ""
81
 
82
+ #: class-wc-facebookcommerce.php:436
83
  #. translators: No items found text
84
  msgid "No %s found."
85
  msgstr ""
86
 
87
+ #: class-wc-facebookcommerce.php:438
88
  #. translators: Search label
89
  msgid "Search %s."
90
  msgstr ""
91
 
92
+ #: class-wc-facebookcommerce.php:440
93
  #. translators: Text label
94
  msgid "Separate %s with commas"
95
  msgstr ""
96
 
97
+ #: class-wc-facebookcommerce.php:442
98
  #. translators: Text label
99
  msgid "Choose from the most used %s"
100
  msgstr ""
101
 
102
+ #: class-wc-facebookcommerce.php:558
103
  msgid "Cannot create the API instance because the access token is missing."
104
  msgstr ""
105
 
includes/Admin/Google_Product_Category_Field.php CHANGED
@@ -64,7 +64,7 @@ class Google_Product_Category_Field {
64
  if ( ! empty( $categories ) ) {
65
 
66
  set_transient( self::OPTION_GOOGLE_PRODUCT_CATEGORIES, $categories, WEEK_IN_SECONDS );
67
- update_option( self::OPTION_GOOGLE_PRODUCT_CATEGORIES, $categories );
68
  }
69
  }
70
 
64
  if ( ! empty( $categories ) ) {
65
 
66
  set_transient( self::OPTION_GOOGLE_PRODUCT_CATEGORIES, $categories, WEEK_IN_SECONDS );
67
+ update_option( self::OPTION_GOOGLE_PRODUCT_CATEGORIES, $categories, 'no' );
68
  }
69
  }
70
 
includes/Lifecycle.php CHANGED
@@ -42,6 +42,7 @@ class Lifecycle extends Framework\Plugin\Lifecycle {
42
  '2.0.0',
43
  '2.0.3',
44
  '2.0.4',
 
45
  ];
46
  }
47
 
@@ -336,5 +337,17 @@ class Lifecycle extends Framework\Plugin\Lifecycle {
336
  }
337
  }
338
 
 
 
 
 
 
 
 
 
 
 
 
 
339
 
340
  }
42
  '2.0.0',
43
  '2.0.3',
44
  '2.0.4',
45
+ '2.3.3',
46
  ];
47
  }
48
 
337
  }
338
  }
339
 
340
+ /**
341
+ * Upgrades to version 2.3.3
342
+ *
343
+ * @since 2.3.3.
344
+ */
345
+ protected function upgrade_to_2_3_3() {
346
+ $sync_enabled = 'yes' === get_option( \WC_Facebookcommerce_Integration::SETTING_ENABLE_PRODUCT_SYNC, 'yes' );
347
+ if ( ! $sync_enabled ) {
348
+ return;
349
+ }
350
+ facebook_for_woocommerce()->get_products_sync_handler()->create_or_update_all_products();
351
+ }
352
 
353
  }
includes/Products.php CHANGED
@@ -1127,17 +1127,19 @@ class Products {
1127
  $value = $product->get_meta( self::ENHANCED_CATALOG_ATTRIBUTES_META_KEY_PREFIX . $key );
1128
 
1129
  if ( empty( $value ) ) {
 
 
1130
  // Check normal product attributes
1131
  foreach ( $product->get_attributes() as $slug => $attribute ) {
1132
  if ( $product->is_type( 'variation' ) ) {
1133
- $attr_name = $slug;
1134
- $attr_val = $attribute;
1135
  } else {
1136
  $attr_name = $attribute->get_name();
1137
  $attr_val = $product->get_attribute( $slug );
1138
  }
1139
 
1140
- if ( strtolower( $attr_name ) === $key ) {
1141
  $value = $attr_val;
1142
  break;
1143
  }
1127
  $value = $product->get_meta( self::ENHANCED_CATALOG_ATTRIBUTES_META_KEY_PREFIX . $key );
1128
 
1129
  if ( empty( $value ) ) {
1130
+ $product_id = $product->get_id();
1131
+
1132
  // Check normal product attributes
1133
  foreach ( $product->get_attributes() as $slug => $attribute ) {
1134
  if ( $product->is_type( 'variation' ) ) {
1135
+ $attr_name = $slug;
1136
+ $attr_val = \WC_Facebookcommerce_Utils::get_variant_option_name( $product_id, 'attribute_' . $slug, $attribute );
1137
  } else {
1138
  $attr_name = $attribute->get_name();
1139
  $attr_val = $product->get_attribute( $slug );
1140
  }
1141
 
1142
+ if ( \WC_Facebookcommerce_Utils::sanitize_variant_name( $attr_name, false ) === $key ) {
1143
  $value = $attr_val;
1144
  break;
1145
  }
includes/fbproduct.php CHANGED
@@ -439,13 +439,6 @@ if ( ! class_exists( 'WC_Facebook_Product' ) ) :
439
  );
440
  }
441
 
442
- public function get_variant_option_name( $label, $default_value ) {
443
- // For the given label, get the Visible name rather than the slug
444
- $meta = get_post_meta( $this->id, $label, true );
445
- $attribute_name = str_replace( 'attribute_', '', $label );
446
- $term = get_term_by( 'slug', $meta, $attribute_name );
447
- return $term && $term->name ? $term->name : $default_value;
448
- }
449
 
450
  public function update_visibility( $is_product_page, $visible_box_checked ) {
451
  $visibility = get_post_meta( $this->id, self::FB_VISIBILITY, true );
@@ -670,7 +663,8 @@ if ( ! class_exists( 'WC_Facebook_Product' ) ) :
670
  $enhanced_data = array();
671
 
672
  $category = $category_handler->get_category_with_attrs( $google_category_id );
673
- $all_attributes = $category['attributes'];
 
674
  foreach ( $all_attributes as $attribute ) {
675
  $value = Products::get_enhanced_catalog_attribute( $attribute['key'], $this->woo_product );
676
  $convert_to_array = (
@@ -692,6 +686,33 @@ if ( ! class_exists( 'WC_Facebook_Product' ) ) :
692
  return array_merge( $product_data, $enhanced_data );
693
  }
694
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
695
  /**
696
  * Normalizes variant data for Facebook.
697
  *
@@ -729,14 +750,12 @@ if ( ! class_exists( 'WC_Facebook_Product' ) ) :
729
  $label = wc_attribute_label( $original_variant_name, $product );
730
 
731
  // Clean up variant name (e.g. pa_color should be color)
732
- // Replace "custom_data:foo" with just "foo" so we can use the key
733
- // Product item API expects "custom_data" instead of "custom_data:foo"
734
- $new_name = str_replace( 'custom_data:', '', \WC_Facebookcommerce_Utils::sanitize_variant_name( $original_variant_name ) );
735
 
736
  // Sometimes WC returns an array, sometimes it's an assoc array, depending
737
  // on what type of taxonomy it's using. array_values will guarantee we
738
  // only get a flat array of values.
739
- if ( $options = $this->get_variant_option_name( $label, $attributes[ $original_variant_name ] ) ) {
740
 
741
  if ( is_array( $options ) ) {
742
 
439
  );
440
  }
441
 
 
 
 
 
 
 
 
442
 
443
  public function update_visibility( $is_product_page, $visible_box_checked ) {
444
  $visibility = get_post_meta( $this->id, self::FB_VISIBILITY, true );
663
  $enhanced_data = array();
664
 
665
  $category = $category_handler->get_category_with_attrs( $google_category_id );
666
+ $all_attributes = $this->get_matched_attributes_for_product( $this->woo_product, $category['attributes'] );
667
+
668
  foreach ( $all_attributes as $attribute ) {
669
  $value = Products::get_enhanced_catalog_attribute( $attribute['key'], $this->woo_product );
670
  $convert_to_array = (
686
  return array_merge( $product_data, $enhanced_data );
687
  }
688
 
689
+
690
+ /**
691
+ * Filters list of attributes to only those available for a given product
692
+ *
693
+ * @param \WC_Product $product WooCommerce Product
694
+ * @param array $all_attributes List of Enhanced Catalog attributes to match
695
+ * @return array
696
+ */
697
+ public function get_matched_attributes_for_product( $product, $all_attributes ) {
698
+ $matched_attributes = array();
699
+ $sanitized_keys = array_map(
700
+ function( $key ) {
701
+ return \WC_Facebookcommerce_Utils::sanitize_variant_name( $key, false );
702
+ },
703
+ array_keys( $product->get_attributes() )
704
+ );
705
+
706
+ $matched_attributes = array_filter( $all_attributes,
707
+ function( $attribute ) use ($sanitized_keys) {
708
+ return in_array( $attribute['key'], $sanitized_keys );
709
+ }
710
+ );
711
+
712
+ return $matched_attributes;
713
+ }
714
+
715
+
716
  /**
717
  * Normalizes variant data for Facebook.
718
  *
750
  $label = wc_attribute_label( $original_variant_name, $product );
751
 
752
  // Clean up variant name (e.g. pa_color should be color)
753
+ $new_name = \WC_Facebookcommerce_Utils::sanitize_variant_name( $original_variant_name, false );
 
 
754
 
755
  // Sometimes WC returns an array, sometimes it's an assoc array, depending
756
  // on what type of taxonomy it's using. array_values will guarantee we
757
  // only get a flat array of values.
758
+ if ( $options = \WC_Facebookcommerce_Utils::get_variant_option_name( $this->id, $label, $attributes[ $original_variant_name ] ) ) {
759
 
760
  if ( is_array( $options ) ) {
761
 
includes/fbutils.php CHANGED
@@ -418,10 +418,22 @@ if ( ! class_exists( 'WC_Facebookcommerce_Utils' ) ) :
418
  return ( self::$store_name ) ? ( self::$store_name ) : 'A Store Has No Name';
419
  }
420
 
 
 
 
 
 
 
 
 
 
 
 
 
421
  /*
422
  * Change variant product field name from Woo taxonomy to FB name
423
  */
424
- public static function sanitize_variant_name( $name ) {
425
  $name = str_replace( array( 'attribute_', 'pa_' ), '', strtolower( $name ) );
426
 
427
  // British spelling
@@ -429,15 +441,17 @@ if ( ! class_exists( 'WC_Facebookcommerce_Utils' ) ) :
429
  $name = self::FB_VARIANT_COLOR;
430
  }
431
 
432
- switch ( $name ) {
433
- case self::FB_VARIANT_SIZE:
434
- case self::FB_VARIANT_COLOR:
435
- case self::FB_VARIANT_GENDER:
436
- case self::FB_VARIANT_PATTERN:
437
- break;
438
- default:
439
- $name = 'custom_data:' . strtolower( $name );
440
- break;
 
 
441
  }
442
 
443
  return $name;
418
  return ( self::$store_name ) ? ( self::$store_name ) : 'A Store Has No Name';
419
  }
420
 
421
+
422
+ /*
423
+ * Get visible name for variant attribute rather than the slug
424
+ */
425
+ public function get_variant_option_name( $wp_id, $label, $default_value ) {
426
+ $meta = get_post_meta( $wp_id, $label, true );
427
+ $attribute_name = str_replace( 'attribute_', '', $label );
428
+ $term = get_term_by( 'slug', $meta, $attribute_name );
429
+ return $term && $term->name ? $term->name : $default_value;
430
+ }
431
+
432
+
433
  /*
434
  * Change variant product field name from Woo taxonomy to FB name
435
  */
436
+ public static function sanitize_variant_name( $name, $use_custom_data = true ) {
437
  $name = str_replace( array( 'attribute_', 'pa_' ), '', strtolower( $name ) );
438
 
439
  // British spelling
441
  $name = self::FB_VARIANT_COLOR;
442
  }
443
 
444
+ if ( $use_custom_data ) {
445
+ switch ( $name ) {
446
+ case self::FB_VARIANT_SIZE:
447
+ case self::FB_VARIANT_COLOR:
448
+ case self::FB_VARIANT_GENDER:
449
+ case self::FB_VARIANT_PATTERN:
450
+ break;
451
+ default:
452
+ $name = 'custom_data:' . strtolower( $name );
453
+ break;
454
+ }
455
  }
456
 
457
  return $name;
readme.txt CHANGED
@@ -3,7 +3,7 @@ Contributors: facebook, automattic, woothemes
3
  Tags: facebook, shop, catalog, advertise, pixel, product
4
  Requires at least: 4.4
5
  Tested up to: 5.6
6
- Stable tag: 2.3.2
7
  Requires PHP: 5.6 or greater
8
  MySQL: 5.6 or greater
9
  License: GPLv2 or later
@@ -39,6 +39,12 @@ When opening a bug on GitHub, please give us as many details as possible.
39
 
40
  == Changelog ==
41
 
 
 
 
 
 
 
42
  = 2021.03.02 - version 2.3.2 =
43
  * Tweak - Bump Facebook Marketing API version to 9.0
44
 
@@ -51,7 +57,7 @@ When opening a bug on GitHub, please give us as many details as possible.
51
  * Feature - Add support for Facebook App store flow
52
  * Tweak - Ask merchants to delete products when changing from sync to not sync state
53
  * Tweak - Remove business_management permission from login scopes
54
- * Tweak - Store paramaters for Commerce merchant settings ID and Instagram business ID
55
  * Fix - Fix Products::get_google_product_category_id_from_highest_category() to handle WP_Error
56
  * Fix - Fix random HELLO appearing in the category settings
57
  * Fix - Make sure that list of strings params are now converted to actual arrays. Fixes an issue with the use of the additional_features parameter
3
  Tags: facebook, shop, catalog, advertise, pixel, product
4
  Requires at least: 4.4
5
  Tested up to: 5.6
6
+ Stable tag: 2.3.3
7
  Requires PHP: 5.6 or greater
8
  MySQL: 5.6 or greater
9
  License: GPLv2 or later
39
 
40
  == Changelog ==
41
 
42
+ = 2021.03.22 - version 2.3.3 =
43
+ * Fix - WooCommerce variation attribute sync not matching Enhanced Catalog attributes.
44
+ * Fix - Enable display names to be used for variant attribute values.
45
+ * Fix - Performance, do not auto-load Google Categories option.
46
+ * Fix - Logs being recorded even with debug option disabled.
47
+
48
  = 2021.03.02 - version 2.3.2 =
49
  * Tweak - Bump Facebook Marketing API version to 9.0
50
 
57
  * Feature - Add support for Facebook App store flow
58
  * Tweak - Ask merchants to delete products when changing from sync to not sync state
59
  * Tweak - Remove business_management permission from login scopes
60
+ * Tweak - Store parameters for Commerce merchant settings ID and Instagram business ID
61
  * Fix - Fix Products::get_google_product_category_id_from_highest_category() to handle WP_Error
62
  * Fix - Fix random HELLO appearing in the category settings
63
  * Fix - Make sure that list of strings params are now converted to actual arrays. Fixes an issue with the use of the additional_features parameter