Facebook for WooCommerce - Version 2.1.2

Version Description

Download this release

Release Info

Developer SkyVerge
Plugin Icon Facebook for WooCommerce
Version 2.1.2
Comparing to
See all releases

Code changes from version 2.1.1 to 2.1.2

assets/js/admin/facebook-for-woocommerce-products-admin.js CHANGED
@@ -169,7 +169,7 @@ jQuery( document ).ready( function( $ ) {
169
 
170
  $container.find( '#product-not-ready-notice, #variable-product-not-ready-notice' ).hide();
171
 
172
- if ( $( 'select#product-type' ).val().match( /variable/ ) && ! isSyncEnabledForVariableProduct() ) {
173
  $container.find( '#variable-product-not-ready-notice' ).show();
174
  } else if ( ! enabled ) {
175
  $container.find( '#product-not-ready-notice' ).show();
@@ -211,7 +211,7 @@ jQuery( document ).ready( function( $ ) {
211
  */
212
  function isSyncEnabledForProduct() {
213
 
214
- if ( $( 'select#product-type' ).val().match( /variable/ ) ) {
215
  return isSyncEnabledForVariableProduct();
216
  }
217
 
@@ -262,7 +262,7 @@ jQuery( document ).ready( function( $ ) {
262
  */
263
  function isPriceDefinedForProduct() {
264
 
265
- if ( $( 'select#product-type' ).val().match( /variable/ ) ) {
266
  // TODO: determine whether variations enabled for sync have a Regular Price or Facebook Price defined {WV 2020-09-19}
267
  return true;
268
  }
@@ -271,6 +271,21 @@ jQuery( document ).ready( function( $ ) {
271
  }
272
 
273
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
274
  /**
275
  * Determines whether a simple product has a Regular Price or Facebook Price defined.
276
  *
@@ -280,7 +295,7 @@ jQuery( document ).ready( function( $ ) {
280
  */
281
  function isPriceDefinedForSimpleProduct() {
282
 
283
- return $( '#_regular_price' ).val().length || $( '#fb_product_price' ).val().length;
284
  }
285
 
286
 
@@ -308,7 +323,7 @@ jQuery( document ).ready( function( $ ) {
308
  */
309
  function isStockManagementEnabledForSimpleProduct() {
310
 
311
- return $( '#_manage_stock' ).prop( 'checked' ) && $( '#_stock' ).val().length;
312
  }
313
 
314
 
169
 
170
  $container.find( '#product-not-ready-notice, #variable-product-not-ready-notice' ).hide();
171
 
172
+ if ( isVariableProduct() && ! isSyncEnabledForVariableProduct() ) {
173
  $container.find( '#variable-product-not-ready-notice' ).show();
174
  } else if ( ! enabled ) {
175
  $container.find( '#product-not-ready-notice' ).show();
211
  */
212
  function isSyncEnabledForProduct() {
213
 
214
+ if ( isVariableProduct() ) {
215
  return isSyncEnabledForVariableProduct();
216
  }
217
 
262
  */
263
  function isPriceDefinedForProduct() {
264
 
265
+ if ( isVariableProduct() ) {
266
  // TODO: determine whether variations enabled for sync have a Regular Price or Facebook Price defined {WV 2020-09-19}
267
  return true;
268
  }
271
  }
272
 
273
 
274
+ /**
275
+ * Determines whether the product is a Variable product.
276
+ *
277
+ * @since 2.1.2
278
+ *
279
+ * @return {boolean}
280
+ */
281
+ function isVariableProduct() {
282
+
283
+ var productType = $( 'select#product-type' ).val();
284
+
285
+ return !! ( productType && productType.match( /variable/ ) );
286
+ }
287
+
288
+
289
  /**
290
  * Determines whether a simple product has a Regular Price or Facebook Price defined.
291
  *
295
  */
296
  function isPriceDefinedForSimpleProduct() {
297
 
298
+ return !! ( $( '#_regular_price' ).val() || $( '#fb_product_price' ).val() );
299
  }
300
 
301
 
323
  */
324
  function isStockManagementEnabledForSimpleProduct() {
325
 
326
+ return !! ( $( '#_manage_stock' ).prop( 'checked' ) && $( '#_stock' ).val() );
327
  }
328
 
329
 
assets/js/admin/facebook-for-woocommerce-products-admin.min.js CHANGED
@@ -1 +1 @@
1
- "use strict";jQuery(document).ready(function(r){var t,e,c,n,i,o,s,a,_,d,l,u,p,f,m,g=window.pagenow.length?window.pagenow:"";window.typenow.length&&window.typenow;"edit-product"===g&&(t=!1,r("input#doaction, input#doaction2").on("click",function(o){if(t)return!0;o.preventDefault();var e,c=r(this),o=c.prev("select").val();"facebook_include"===o?(e=[],r.each(r('input[name="post[]"]:checked'),function(){e.push(parseInt(r(this).val(),10))}),r.post(facebook_for_woocommerce_products_admin.ajax_url,{action:"facebook_for_woocommerce_set_product_sync_bulk_action_prompt",security:facebook_for_woocommerce_products_admin.set_product_sync_bulk_action_prompt_nonce,toggle:o,products:e},function(o){o&&!o.success?(r("#wc-backbone-modal-dialog .modal-close").trigger("click"),new r.WCBackboneModal.View({target:"facebook-for-woocommerce-modal",string:o.data})):(t=!0,c.trigger("click"))})):(t=!0,c.trigger("click"))})),"product"===g&&(e=function(o,e){e.find(".enable-if-sync-enabled").prop("disabled",!o)},c=function(o,e){o?(e.find("option[value='sync_and_show']").show(),e.prop("original")&&e.val(e.prop("original"))):(e.find("option[value='sync_and_show']").hide(),"sync_and_show"===e.val()&&e.val("sync_and_hide"))},n=function(o,e){var c=e.find("#wc_facebook_commerce_enabled"),t=c.prop("original");c.prop("checked",!!o&&t).prop("disabled",!o),c.trigger("change"),c.prop("original",t),e.find("#product-not-ready-notice, #variable-product-not-ready-notice").hide(),r("select#product-type").val().match(/variable/)&&!s()?e.find("#variable-product-not-ready-notice").show():o||e.find("#product-not-ready-notice").show()},i=function(){return!!o()&&(!!_()&&!!l())},o=function(){return(r("select#product-type").val().match(/variable/)?s:a)()},s=function(){var o=r(".js-variable-fb-sync-toggle");return 0===o.length?!!facebook_for_woocommerce_products_admin.is_sync_enabled_for_product:!!o.map(function(o,e){return"sync_disabled"!==r(e).val()?e:null}).length},a=function(){return"sync_disabled"!==r("#wc_facebook_sync_mode").val()},_=function(){return!!r("select#product-type").val().match(/variable/)||d()},d=function(){return r("#_regular_price").val().length||r("#fb_product_price").val().length},l=function(){return u()},u=function(){return r("#_manage_stock").prop("checked")&&r("#_stock").val().length},r("#facebook_options #wc_facebook_commerce_enabled").on("change",function(){var o=r(this).prop("checked");o?r(".wc_facebook_commerce_fields").show():r(".wc_facebook_commerce_fields").hide(),r(".product_attributes").find(".woocommerce_attribute").length?r(".show_if_has_attributes").show():r(".show_if_has_attributes").hide(),r(this).prop("original",o)}).trigger("change"),p=r("#wc_facebook_sync_mode"),f=p.closest(".woocommerce_options_panel"),p.on("change",function(){var o="sync_disabled"!==r(this).val();e(o,f),function(o,e){e=e.find(".wc-facebook-commerce-options-group");o?e.show():e.hide()}(o,f),p.prop("original",r(this).val())}).trigger("change"),r("#_virtual").on("change",function(){c(!r(this).prop("checked"),p)}).trigger("change"),r("#woocommerce-product-data").on("change","#_regular_price, #_manage_stock, #_stock, #wc_facebook_sync_mode, #fb_product_price",function(o){setTimeout(function(){n(i(),r("#facebook_options"))},1)}),r(".woocommerce_variations").on("change",".js-variable-fb-sync-toggle",function(){e("sync_disabled"!==r(this).val(),r(this).closest(".wc-metabox-content")),n(i(),r("#facebook_options")),r(this).prop("original",r(this).val())}),r("#woocommerce-product-data").on("woocommerce_variations_loaded",function(){r(".js-variable-fb-sync-toggle").each(function(){e("sync_disabled"!==r(this).val(),r(this).closest(".wc-metabox-content")),r(this).prop("original",r(this).val())}),r(".variable_is_virtual").on("change",function(){var o=r(this).closest(".wc-metabox-content").find(".js-variable-fb-sync-toggle");c(!r(this).prop("checked"),o)}),n(i(),r("#facebook_options"))}),r("#woocommerce-product-data").on("change",".js-fb-product-image-source",function(){var o=r(this).closest(".woocommerce_options_panel, .wc-metabox-content"),e=r(this).val();o.find(".product-image-source-field").closest(".form-field").hide(),o.find(".show-if-product-image-source-"+e).closest(".form-field").show()}),r(".js-fb-product-image-source:checked:visible").trigger("change"),r("#woocommerce-product-data").on("woocommerce_variations_loaded",function(){r(".js-variable-fb-sync-toggle:visible").trigger("change"),r(".js-fb-product-image-source:checked:visible").trigger("change"),r(".variable_is_virtual:visible").trigger("change")}),r("#facebook_options").on("click","#product-not-ready-notice-open-modal",function(o){o.preventDefault(),r("#wc-backbone-modal-dialog .modal-close").trigger("click"),new r.WCBackboneModal.View({target:"facebook-for-woocommerce-modal",string:{message:facebook_for_woocommerce_products_admin.product_not_ready_modal_message,buttons:facebook_for_woocommerce_products_admin.product_not_ready_modal_buttons}})}),n(i(),f),m=!1,r('form#post input[type="submit"]').on("click",function(o){if(!!r("#wc_facebook_commerce_enabled").prop("checked")&&(!!i()&&r(".wc_facebook_commerce_fields .wc-facebook-google-product-category-select").map(function(o,e){return r(e).val()?r(e).val():null}).length<2))return o.preventDefault(),alert(facebook_for_woocommerce_products_admin.i18n.missing_google_product_category_message),!1;if(m)return!0;o.preventDefault();var e=r(this),c=parseInt(r("input#post_ID").val(),10),t=[],n=r('textarea[name="tax_input[product_tag]"]').length?r('textarea[name="tax_input[product_tag]"]').val().split(","):[],a="sync_disabled"!==r("#wc_facebook_sync_mode").val(),o=s();r('#taxonomy-product_cat input[name="tax_input[product_cat][]"]:checked').each(function(){t.push(parseInt(r(this).val(),10))}),r('#taxonomy-product_tag input[name="tax_input[product_tag][]"]:checked').each(function(){n.push(parseInt(r(this).val(),10))}),0<c?r.post(facebook_for_woocommerce_products_admin.ajax_url,{action:"facebook_for_woocommerce_set_product_sync_prompt",security:facebook_for_woocommerce_products_admin.set_product_sync_prompt_nonce,sync_enabled:a?"enabled":"disabled",var_sync_enabled:o?"enabled":"disabled",product:c,categories:t,tags:n},function(o){o&&!o.success&&a?(r("#wc-backbone-modal-dialog .modal-close").trigger("click"),new r.WCBackboneModal.View({target:"facebook-for-woocommerce-modal",string:o.data})):(m=!0,e.trigger("click"))}):(m=!0,e.trigger("click"))}))});
1
+ "use strict";jQuery(document).ready(function(r){var t,e,c,n,i,o,s,a,_,d,l,u,p,f,m,g,b=window.pagenow.length?window.pagenow:"";window.typenow.length&&window.typenow;"edit-product"===b&&(t=!1,r("input#doaction, input#doaction2").on("click",function(o){if(t)return!0;o.preventDefault();var e,c=r(this),o=c.prev("select").val();"facebook_include"===o?(e=[],r.each(r('input[name="post[]"]:checked'),function(){e.push(parseInt(r(this).val(),10))}),r.post(facebook_for_woocommerce_products_admin.ajax_url,{action:"facebook_for_woocommerce_set_product_sync_bulk_action_prompt",security:facebook_for_woocommerce_products_admin.set_product_sync_bulk_action_prompt_nonce,toggle:o,products:e},function(o){o&&!o.success?(r("#wc-backbone-modal-dialog .modal-close").trigger("click"),new r.WCBackboneModal.View({target:"facebook-for-woocommerce-modal",string:o.data})):(t=!0,c.trigger("click"))})):(t=!0,c.trigger("click"))})),"product"===b&&(e=function(o,e){e.find(".enable-if-sync-enabled").prop("disabled",!o)},c=function(o,e){o?(e.find("option[value='sync_and_show']").show(),e.prop("original")&&e.val(e.prop("original"))):(e.find("option[value='sync_and_show']").hide(),"sync_and_show"===e.val()&&e.val("sync_and_hide"))},n=function(o,e){var c=e.find("#wc_facebook_commerce_enabled"),t=c.prop("original");c.prop("checked",!!o&&t).prop("disabled",!o),c.trigger("change"),c.prop("original",t),e.find("#product-not-ready-notice, #variable-product-not-ready-notice").hide(),d()&&!s()?e.find("#variable-product-not-ready-notice").show():o||e.find("#product-not-ready-notice").show()},i=function(){return!!o()&&(!!_()&&!!u())},o=function(){return(d()?s:a)()},s=function(){var o=r(".js-variable-fb-sync-toggle");return 0===o.length?!!facebook_for_woocommerce_products_admin.is_sync_enabled_for_product:!!o.map(function(o,e){return"sync_disabled"!==r(e).val()?e:null}).length},a=function(){return"sync_disabled"!==r("#wc_facebook_sync_mode").val()},_=function(){return!!d()||l()},d=function(){var o=r("select#product-type").val();return!(!o||!o.match(/variable/))},l=function(){return!(!r("#_regular_price").val()&&!r("#fb_product_price").val())},u=function(){return p()},p=function(){return!(!r("#_manage_stock").prop("checked")||!r("#_stock").val())},r("#facebook_options #wc_facebook_commerce_enabled").on("change",function(){var o=r(this).prop("checked");o?r(".wc_facebook_commerce_fields").show():r(".wc_facebook_commerce_fields").hide(),r(".product_attributes").find(".woocommerce_attribute").length?r(".show_if_has_attributes").show():r(".show_if_has_attributes").hide(),r(this).prop("original",o)}).trigger("change"),f=r("#wc_facebook_sync_mode"),m=f.closest(".woocommerce_options_panel"),f.on("change",function(){var o="sync_disabled"!==r(this).val();e(o,m),function(o,e){e=e.find(".wc-facebook-commerce-options-group");o?e.show():e.hide()}(o,m),f.prop("original",r(this).val())}).trigger("change"),r("#_virtual").on("change",function(){c(!r(this).prop("checked"),f)}).trigger("change"),r("#woocommerce-product-data").on("change","#_regular_price, #_manage_stock, #_stock, #wc_facebook_sync_mode, #fb_product_price",function(o){setTimeout(function(){n(i(),r("#facebook_options"))},1)}),r(".woocommerce_variations").on("change",".js-variable-fb-sync-toggle",function(){e("sync_disabled"!==r(this).val(),r(this).closest(".wc-metabox-content")),n(i(),r("#facebook_options")),r(this).prop("original",r(this).val())}),r("#woocommerce-product-data").on("woocommerce_variations_loaded",function(){r(".js-variable-fb-sync-toggle").each(function(){e("sync_disabled"!==r(this).val(),r(this).closest(".wc-metabox-content")),r(this).prop("original",r(this).val())}),r(".variable_is_virtual").on("change",function(){var o=r(this).closest(".wc-metabox-content").find(".js-variable-fb-sync-toggle");c(!r(this).prop("checked"),o)}),n(i(),r("#facebook_options"))}),r("#woocommerce-product-data").on("change",".js-fb-product-image-source",function(){var o=r(this).closest(".woocommerce_options_panel, .wc-metabox-content"),e=r(this).val();o.find(".product-image-source-field").closest(".form-field").hide(),o.find(".show-if-product-image-source-"+e).closest(".form-field").show()}),r(".js-fb-product-image-source:checked:visible").trigger("change"),r("#woocommerce-product-data").on("woocommerce_variations_loaded",function(){r(".js-variable-fb-sync-toggle:visible").trigger("change"),r(".js-fb-product-image-source:checked:visible").trigger("change"),r(".variable_is_virtual:visible").trigger("change")}),r("#facebook_options").on("click","#product-not-ready-notice-open-modal",function(o){o.preventDefault(),r("#wc-backbone-modal-dialog .modal-close").trigger("click"),new r.WCBackboneModal.View({target:"facebook-for-woocommerce-modal",string:{message:facebook_for_woocommerce_products_admin.product_not_ready_modal_message,buttons:facebook_for_woocommerce_products_admin.product_not_ready_modal_buttons}})}),n(i(),m),g=!1,r('form#post input[type="submit"]').on("click",function(o){if(!!r("#wc_facebook_commerce_enabled").prop("checked")&&(!!i()&&r(".wc_facebook_commerce_fields .wc-facebook-google-product-category-select").map(function(o,e){return r(e).val()?r(e).val():null}).length<2))return o.preventDefault(),alert(facebook_for_woocommerce_products_admin.i18n.missing_google_product_category_message),!1;if(g)return!0;o.preventDefault();var e=r(this),c=parseInt(r("input#post_ID").val(),10),t=[],n=r('textarea[name="tax_input[product_tag]"]').length?r('textarea[name="tax_input[product_tag]"]').val().split(","):[],a="sync_disabled"!==r("#wc_facebook_sync_mode").val(),o=s();r('#taxonomy-product_cat input[name="tax_input[product_cat][]"]:checked').each(function(){t.push(parseInt(r(this).val(),10))}),r('#taxonomy-product_tag input[name="tax_input[product_tag][]"]:checked').each(function(){n.push(parseInt(r(this).val(),10))}),0<c?r.post(facebook_for_woocommerce_products_admin.ajax_url,{action:"facebook_for_woocommerce_set_product_sync_prompt",security:facebook_for_woocommerce_products_admin.set_product_sync_prompt_nonce,sync_enabled:a?"enabled":"disabled",var_sync_enabled:o?"enabled":"disabled",product:c,categories:t,tags:n},function(o){o&&!o.success&&a?(r("#wc-backbone-modal-dialog .modal-close").trigger("click"),new r.WCBackboneModal.View({target:"facebook-for-woocommerce-modal",string:o.data})):(g=!0,e.trigger("click"))}):(g=!0,e.trigger("click"))}))});
changelog.txt CHANGED
@@ -1,5 +1,10 @@
1
  *** Facebook for WooCommerce Changelog ***
2
 
 
 
 
 
 
3
  2020.10.27 - version 2.1.1
4
  * Fix - Adjust code syntax that may have issued errors in installations running PHP lower than 7.3
5
 
1
  *** Facebook for WooCommerce Changelog ***
2
 
3
+ 2020.10.28 - version 2.1.2
4
+ * Tweak - Default variation selection will be synced to Facebook if the default product variation is already synced
5
+ * Fix - Trigger a pixel Search event for product search requests with a single result (works for logged in users or visitors with an active WooCommerce session)
6
+ * Fix - Prevent a JavaScript error on the Add New Product page when Facebook for WooCommerce is not connected to Facebook
7
+
8
  2020.10.27 - version 2.1.1
9
  * Fix - Adjust code syntax that may have issued errors in installations running PHP lower than 7.3
10
 
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.1.1';
26
 
27
  /** @var string for backwards compatibility TODO: remove this in v2.0.0 {CW 2020-02-06} */
28
  const PLUGIN_VERSION = self::VERSION;
22
 
23
 
24
  /** @var string the plugin version */
25
+ const VERSION = '2.1.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;
facebook-commerce-events-tracker.php CHANGED
@@ -27,6 +27,10 @@ if ( ! class_exists( 'WC_Facebookcommerce_EventsTracker' ) ) :
27
  const FB_PRIORITY_HIGH = 2;
28
  const FB_PRIORITY_LOW = 11;
29
 
 
 
 
 
30
  /** @var Event search event instance */
31
  private $search_event;
32
  /** @var array with events tracked */
@@ -53,6 +57,7 @@ if ( ! class_exists( 'WC_Facebookcommerce_EventsTracker' ) ) :
53
 
54
  // ViewContent for individual products
55
  add_action( 'woocommerce_after_single_product', [ $this, 'inject_view_content_event' ] );
 
56
 
57
  add_action(
58
  'woocommerce_after_shop_loop',
@@ -62,6 +67,7 @@ if ( ! class_exists( 'WC_Facebookcommerce_EventsTracker' ) ) :
62
  'pre_get_posts',
63
  array( $this, 'inject_search_event' )
64
  );
 
65
 
66
  // AddToCart events
67
  add_action( 'woocommerce_add_to_cart', [ $this, 'inject_add_to_cart_event' ], 40, 4 );
@@ -187,6 +193,128 @@ if ( ! class_exists( 'WC_Facebookcommerce_EventsTracker' ) ) :
187
  $this->pixel->inject_event( $event_name, $event_data, 'trackCustom' );
188
  }
189
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
190
  /**
191
  * Triggers Search for result pages (deduped)
192
  *
27
  const FB_PRIORITY_HIGH = 2;
28
  const FB_PRIORITY_LOW = 11;
29
 
30
+
31
+ /** @var string name of the session variable used to store search event data */
32
+ private $search_event_data_session_variable = 'wc_facebook_search_event_data';
33
+
34
  /** @var Event search event instance */
35
  private $search_event;
36
  /** @var array with events tracked */
57
 
58
  // ViewContent for individual products
59
  add_action( 'woocommerce_after_single_product', [ $this, 'inject_view_content_event' ] );
60
+ add_action( 'woocommerce_after_single_product', [ $this, 'maybe_inject_search_event' ] );
61
 
62
  add_action(
63
  'woocommerce_after_shop_loop',
67
  'pre_get_posts',
68
  array( $this, 'inject_search_event' )
69
  );
70
+ add_filter( 'woocommerce_redirect_single_search_result', [ $this, 'maybe_add_product_search_event_to_session' ] );
71
 
72
  // AddToCart events
73
  add_action( 'woocommerce_add_to_cart', [ $this, 'inject_add_to_cart_event' ], 40, 4 );
193
  $this->pixel->inject_event( $event_name, $event_data, 'trackCustom' );
194
  }
195
 
196
+
197
+ /**
198
+ * Attempts to add a session variable to indicate that a product search event occurred.
199
+ *
200
+ * The session variable is used to catch search events that have a single result.
201
+ * In those cases WooCommerce redirects customers to the product page instead of showing the search results.
202
+ *
203
+ * The plugin can't inject a Pixel event code on redirect responses, but it can check for the presence of the variable on the product page.
204
+ *
205
+ * This method is hooked to woocommerce_redirect_single_search_result which is triggered right before redirecting.
206
+ *
207
+ * @internal
208
+ *
209
+ * @since 2.1.2
210
+ *
211
+ * @param bool $redirect whether to redirect to the product page
212
+ * @return bool
213
+ */
214
+ public function maybe_add_product_search_event_to_session( $redirect ) {
215
+
216
+ if ( $redirect && $this->search_event && $this->is_single_search_result() ) {
217
+
218
+ $this->add_product_search_event_to_session( $this->search_event );
219
+ }
220
+
221
+ return $redirect;
222
+ }
223
+
224
+
225
+ /**
226
+ * Determines whether the current request is a product search with a single result.
227
+ *
228
+ * @since 2.1.2
229
+ *
230
+ * @return bool
231
+ */
232
+ private function is_single_search_result() {
233
+ global $wp_query;
234
+
235
+ return is_search() && 1 === absint( $wp_query->found_posts ) && is_post_type_archive( 'product' );
236
+ }
237
+
238
+
239
+ /**
240
+ * Adds search event data to the session.
241
+ *
242
+ * This does nothing if there is no session set.
243
+ *
244
+ * @since 2.1.2
245
+ *
246
+ * @return void
247
+ */
248
+ private function add_product_search_event_to_session( Event $event ) {
249
+
250
+ if ( isset( WC()->session ) && is_callable( [ WC()->session, 'has_session' ] ) && WC()->session->has_session() ) {
251
+ WC()->session->set( $this->search_event_data_session_variable, $event->get_data() );
252
+ }
253
+ }
254
+
255
+
256
+ /**
257
+ * Injects a frontend search event if the session has stored event data.
258
+ *
259
+ * @internal
260
+ *
261
+ * @since 2.1.2
262
+ */
263
+ public function maybe_inject_search_event() {
264
+
265
+ if ( ! self::$isEnabled ) {
266
+ return;
267
+ }
268
+
269
+ $this->search_event = $this->get_product_search_event_from_session();
270
+
271
+ if ( ! $this->search_event ) {
272
+ return;
273
+ }
274
+
275
+ $this->delete_session_data( $this->search_event_data_session_variable );
276
+ $this->actually_inject_search_event();
277
+ }
278
+
279
+
280
+ /**
281
+ * Attempts to create an Event instance for a product search event using session data.
282
+ *
283
+ * @since 2.1.2
284
+ *
285
+ * @return Event|null
286
+ */
287
+ private function get_product_search_event_from_session() {
288
+
289
+ if ( ! isset( WC()->session ) || ! is_callable( [ WC()->session, 'get' ] ) ) {
290
+ return null;
291
+ }
292
+
293
+ $data = WC()->session->get( $this->search_event_data_session_variable );
294
+
295
+ if ( ! is_array( $data ) || empty( $data ) ) {
296
+ return null;
297
+ }
298
+
299
+ return new Event( $data );
300
+ }
301
+
302
+
303
+ /**
304
+ * Deletes a session variable.
305
+ *
306
+ * @since 2.1.2
307
+ *
308
+ * @param string $key name of the variable to delete
309
+ */
310
+ private function delete_session_data( $key ) {
311
+
312
+ if ( isset( WC()->session->$key ) ) {
313
+ unset( WC()->session->$key );
314
+ }
315
+ }
316
+
317
+
318
  /**
319
  * Triggers Search for result pages (deduped)
320
  *
facebook-commerce.php CHANGED
@@ -1401,6 +1401,8 @@ class WC_Facebookcommerce_Integration extends WC_Integration {
1401
 
1402
  /**
1403
  * Update existing product group (variant data only)
 
 
1404
  **/
1405
  function update_product_group( $woo_product ) {
1406
  $fb_product_group_id = $this->get_product_fbid(
@@ -1428,9 +1430,24 @@ class WC_Facebookcommerce_Integration extends WC_Integration {
1428
  return;
1429
  }
1430
 
1431
- $product_group_data = array(
 
 
 
 
 
 
 
 
 
 
 
1432
  'variants' => $variants,
1433
- );
 
 
 
 
1434
 
1435
  $result = $this->check_api_result(
1436
  $this->fbgraph->update_product_group(
@@ -1450,6 +1467,63 @@ class WC_Facebookcommerce_Integration extends WC_Integration {
1450
  */
1451
  }
1452
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1453
  /**
1454
  * Update existing product
1455
  **/
1401
 
1402
  /**
1403
  * Update existing product group (variant data only)
1404
+ *
1405
+ * @param \WC_Facebook_Product $woo_product
1406
  **/
1407
  function update_product_group( $woo_product ) {
1408
  $fb_product_group_id = $this->get_product_fbid(
1430
  return;
1431
  }
1432
 
1433
+ // figure out the matching default variation
1434
+ $default_product_fbid = null;
1435
+ $woo_default_variation = $this->get_product_group_default_variation( $woo_product );
1436
+
1437
+ if ( $woo_default_variation ) {
1438
+ $default_product_fbid = $this->get_product_fbid(
1439
+ self::FB_PRODUCT_ITEM_ID,
1440
+ $woo_default_variation['variation_id']
1441
+ );
1442
+ }
1443
+
1444
+ $product_group_data = [
1445
  'variants' => $variants,
1446
+ ];
1447
+
1448
+ if ( $default_product_fbid ) {
1449
+ $product_group_data['default_product_id'] = $default_product_fbid;
1450
+ }
1451
 
1452
  $result = $this->check_api_result(
1453
  $this->fbgraph->update_product_group(
1467
  */
1468
  }
1469
 
1470
+
1471
+ /**
1472
+ * Determines if there is a matching variation for the default attributes.
1473
+ *
1474
+ * @since 2.1.2
1475
+ *
1476
+ * @param \WC_Facebook_Product $woo_product
1477
+ * @return array|null
1478
+ */
1479
+ private function get_product_group_default_variation( $woo_product ) {
1480
+
1481
+ $default_attributes = $woo_product->woo_product->get_default_attributes( 'edit' );
1482
+
1483
+ if ( empty( $default_attributes ) ) {
1484
+ return null;
1485
+ }
1486
+
1487
+ $default_variation = null;
1488
+ $product_variations = $woo_product->woo_product->get_available_variations();
1489
+
1490
+ foreach ( $product_variations as $variation ) {
1491
+
1492
+ $variation_attributes = $this->get_product_variation_attributes( $variation );
1493
+
1494
+ $matching_attributes = array_intersect_assoc( $default_attributes, $variation_attributes );
1495
+
1496
+ if ( count( $matching_attributes ) === count( $variation_attributes ) ) {
1497
+ $default_variation = $variation;
1498
+ break;
1499
+ }
1500
+ }
1501
+
1502
+ return $default_variation;
1503
+ }
1504
+
1505
+
1506
+ /**
1507
+ * Parses given product variation for it's attributes
1508
+ *
1509
+ * @since 2.1.2
1510
+ *
1511
+ * @param array $variation
1512
+ * @return array
1513
+ */
1514
+ private function get_product_variation_attributes( $variation ) {
1515
+
1516
+ $final_attributes = [];
1517
+ $variation_attributes = $variation['attributes'];
1518
+
1519
+ foreach ( $variation_attributes as $attribute_name => $attribute_value ) {
1520
+ $final_attributes[ str_replace( 'attribute_', '', $attribute_name ) ] = $attribute_value;
1521
+ }
1522
+
1523
+ return $final_attributes;
1524
+ }
1525
+
1526
+
1527
  /**
1528
  * Update existing product
1529
  **/
facebook-for-woocommerce.php CHANGED
@@ -10,7 +10,7 @@
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.1.1
14
  * Text Domain: facebook-for-woocommerce
15
  * WC requires at least: 3.5.0
16
  * WC tested up to: 4.6.1
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.1.2
14
  * Text Domain: facebook-for-woocommerce
15
  * WC requires at least: 3.5.0
16
  * WC tested up to: 4.6.1
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.1.1\n"
6
  "Report-Msgid-Bugs-To: "
7
  "https://woocommerce.com/my-account/marketplace-ticket-form/\n"
8
- "POT-Creation-Date: 2020-10-27 11:58:58+00:00\n"
9
  "MIME-Version: 1.0\n"
10
  "Content-Type: text/plain; charset=utf-8\n"
11
  "Content-Transfer-Encoding: 8bit\n"
@@ -87,45 +87,45 @@ msgstr ""
87
  msgid "This product is not yet synced to Facebook."
88
  msgstr ""
89
 
90
- #: facebook-commerce.php:1421
91
  msgid "Nothing to update for product group for %1$s"
92
  msgstr ""
93
 
94
- #: facebook-commerce.php:1687
95
  #. translators: Placeholders %1$s - original error message from Facebook API
96
  msgid "There was an issue connecting to the Facebook API: %1$s"
97
  msgstr ""
98
 
99
- #: facebook-commerce.php:2024
100
  msgid "Your connection has expired."
101
  msgstr ""
102
 
103
- #: facebook-commerce.php:2024
104
  msgid ""
105
  "Please click Manage connection > Advanced Options > Update Token to refresh "
106
  "your connection to Facebook."
107
  msgstr ""
108
 
109
- #: facebook-commerce.php:2031
110
  #. translators: Placeholders %s - error message
111
  msgid "There was an error trying to sync the products to Facebook. %s"
112
  msgstr ""
113
 
114
- #: facebook-commerce.php:2054 facebook-commerce.php:2227
115
  msgid "Product sync is disabled."
116
  msgstr ""
117
 
118
- #: facebook-commerce.php:2061 facebook-commerce.php:2234
119
  msgid "The plugin is not configured or the Catalog ID is missing."
120
  msgstr ""
121
 
122
- #: facebook-commerce.php:2084
123
  msgid ""
124
  "A product sync is in progress. Please wait until the sync finishes before "
125
  "starting a new one."
126
  msgstr ""
127
 
128
- #: facebook-commerce.php:2096 facebook-commerce.php:2248
129
  msgid ""
130
  "We've detected that your Facebook Product Catalog is no longer valid. This "
131
  "may happen if it was deleted, but could also be a temporary error. If the "
@@ -133,33 +133,33 @@ msgid ""
133
  "and setup the plugin again."
134
  msgstr ""
135
 
136
- #: facebook-commerce.php:2272
137
  msgid "We couldn't create the feed or upload the product information."
138
  msgstr ""
139
 
140
- #: facebook-commerce.php:2740
141
  msgid "Hi! We're here to answer any questions you may have."
142
  msgstr ""
143
 
144
- #: facebook-commerce.php:3087
145
  msgid "Facebook for WooCommerce error:"
146
  msgstr ""
147
 
148
- #: facebook-commerce.php:3169
149
  msgid ""
150
  "There was an error trying to retrieve information about the Facebook page: "
151
  "%s"
152
  msgstr ""
153
 
154
- #: facebook-commerce.php:3220
155
  msgid "Get started with Messenger Customer Chat"
156
  msgstr ""
157
 
158
- #: facebook-commerce.php:3221
159
  msgid "Get started with Instagram Shopping"
160
  msgstr ""
161
 
162
- #: facebook-commerce.php:3456
163
  #. translators: Placeholders %1$s - original error message from Facebook API
164
  msgid "There was an issue connecting to the Facebook API: %s"
165
  msgstr ""
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.1.2\n"
6
  "Report-Msgid-Bugs-To: "
7
  "https://woocommerce.com/my-account/marketplace-ticket-form/\n"
8
+ "POT-Creation-Date: 2020-10-28 13:28:32+00:00\n"
9
  "MIME-Version: 1.0\n"
10
  "Content-Type: text/plain; charset=utf-8\n"
11
  "Content-Transfer-Encoding: 8bit\n"
87
  msgid "This product is not yet synced to Facebook."
88
  msgstr ""
89
 
90
+ #: facebook-commerce.php:1423
91
  msgid "Nothing to update for product group for %1$s"
92
  msgstr ""
93
 
94
+ #: facebook-commerce.php:1761
95
  #. translators: Placeholders %1$s - original error message from Facebook API
96
  msgid "There was an issue connecting to the Facebook API: %1$s"
97
  msgstr ""
98
 
99
+ #: facebook-commerce.php:2098
100
  msgid "Your connection has expired."
101
  msgstr ""
102
 
103
+ #: facebook-commerce.php:2098
104
  msgid ""
105
  "Please click Manage connection > Advanced Options > Update Token to refresh "
106
  "your connection to Facebook."
107
  msgstr ""
108
 
109
+ #: facebook-commerce.php:2105
110
  #. translators: Placeholders %s - error message
111
  msgid "There was an error trying to sync the products to Facebook. %s"
112
  msgstr ""
113
 
114
+ #: facebook-commerce.php:2128 facebook-commerce.php:2301
115
  msgid "Product sync is disabled."
116
  msgstr ""
117
 
118
+ #: facebook-commerce.php:2135 facebook-commerce.php:2308
119
  msgid "The plugin is not configured or the Catalog ID is missing."
120
  msgstr ""
121
 
122
+ #: facebook-commerce.php:2158
123
  msgid ""
124
  "A product sync is in progress. Please wait until the sync finishes before "
125
  "starting a new one."
126
  msgstr ""
127
 
128
+ #: facebook-commerce.php:2170 facebook-commerce.php:2322
129
  msgid ""
130
  "We've detected that your Facebook Product Catalog is no longer valid. This "
131
  "may happen if it was deleted, but could also be a temporary error. If the "
133
  "and setup the plugin again."
134
  msgstr ""
135
 
136
+ #: facebook-commerce.php:2346
137
  msgid "We couldn't create the feed or upload the product information."
138
  msgstr ""
139
 
140
+ #: facebook-commerce.php:2814
141
  msgid "Hi! We're here to answer any questions you may have."
142
  msgstr ""
143
 
144
+ #: facebook-commerce.php:3161
145
  msgid "Facebook for WooCommerce error:"
146
  msgstr ""
147
 
148
+ #: facebook-commerce.php:3243
149
  msgid ""
150
  "There was an error trying to retrieve information about the Facebook page: "
151
  "%s"
152
  msgstr ""
153
 
154
+ #: facebook-commerce.php:3294
155
  msgid "Get started with Messenger Customer Chat"
156
  msgstr ""
157
 
158
+ #: facebook-commerce.php:3295
159
  msgid "Get started with Instagram Shopping"
160
  msgstr ""
161
 
162
+ #: facebook-commerce.php:3530
163
  #. translators: Placeholders %1$s - original error message from Facebook API
164
  msgid "There was an issue connecting to the Facebook API: %s"
165
  msgstr ""
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.5.1
6
- Stable tag: 2.1.1
7
  Requires PHP: 5.6 or greater
8
  MySQL: 5.6 or greater
9
  License: GPLv2 or later
@@ -39,6 +39,11 @@ When opening a bug on GitHub, please give us as many details as possible.
39
 
40
  == Changelog ==
41
 
 
 
 
 
 
42
  = 2020.10.27 - version 2.1.1 =
43
  * Fix - Adjust code syntax that may have issued errors in installations running PHP lower than 7.3
44
 
3
  Tags: facebook, shop, catalog, advertise, pixel, product
4
  Requires at least: 4.4
5
  Tested up to: 5.5.1
6
+ Stable tag: 2.1.2
7
  Requires PHP: 5.6 or greater
8
  MySQL: 5.6 or greater
9
  License: GPLv2 or later
39
 
40
  == Changelog ==
41
 
42
+ = 2020.10.28 - version 2.1.2 =
43
+ * Tweak - Default variation selection will be synced to Facebook if the default product variation is already synced
44
+ * Fix - Trigger a pixel Search event for product search requests with a single result (works for logged in users or visitors with an active WooCommerce session)
45
+ * Fix - Prevent a JavaScript error on the Add New Product page when Facebook for WooCommerce is not connected to Facebook
46
+
47
  = 2020.10.27 - version 2.1.1 =
48
  * Fix - Adjust code syntax that may have issued errors in installations running PHP lower than 7.3
49