tag */
@@ -1053,7 +1058,8 @@ public function maybe_add_enabling_virtual_products_sync_notice() {
$show_notice_transient_name = 'wc_' . facebook_for_woocommerce()->get_id() . '_enabling_virtual_products_sync_show_notice_' . get_current_user_id();
$affected_products_transient_name = 'wc_' . facebook_for_woocommerce()->get_id() . '_enabling_virtual_products_sync_affected_products_' . get_current_user_id();
- if ( Helper::is_current_screen( 'edit-product' ) && get_transient( $show_notice_transient_name ) && ( $affected_products = get_transient( $affected_products_transient_name ) ) ) {
+ $affected_products = get_transient( $affected_products_transient_name );
+ if ( Helper::is_current_screen( 'edit-product' ) && get_transient( $show_notice_transient_name ) && $affected_products ) {
$message = sprintf(
esc_html(
@@ -1100,10 +1106,13 @@ public function filter_virtual_products_affected_enabling_sync( $query_vars ) {
$transient_name = 'wc_' . facebook_for_woocommerce()->get_id() . '_enabling_virtual_products_sync_affected_products_' . get_current_user_id();
- if ( isset( $_GET['facebook_show_affected_products'] ) && Helper::is_current_screen( 'edit-product' ) && $affected_products = get_transient( $transient_name ) ) {
+ $affected_products = get_transient( $transient_name );
+ // phpcs:disable WordPress.Security.NonceVerification.Recommended
+ if ( isset( $_GET['facebook_show_affected_products'] ) && Helper::is_current_screen( 'edit-product' ) && $affected_products ) {
$query_vars['post__in'] = $affected_products;
}
+ // phpcs:enable WordPress.Security.NonceVerification.Recommended
return $query_vars;
}
@@ -1196,8 +1205,8 @@ private function render_facebook_product_video_field( $video_urls ) {
?>
-
-
+
+
ID, Products::SYNC_ENABLED_META_KEY, true );
- $is_visible = ( $visibility = get_post_meta( $post->ID, Products::VISIBILITY_META_KEY, true ) ) ? wc_string_to_bool( $visibility ) : true;
+ $visibility = get_post_meta( $post->ID, Products::VISIBILITY_META_KEY, true );
+ $is_visible = $visibility ? wc_string_to_bool( $visibility ) : true;
$product = wc_get_product( $post );
$fb_product_description = get_post_meta( $post->ID, \WC_Facebookcommerce_Integration::FB_PRODUCT_DESCRIPTION, true );
@@ -1267,72 +1277,72 @@ public function add_product_settings_tab_content() {
)
);
- echo '';
- echo '
';
- woocommerce_wp_radio(
- array(
- 'id' => 'fb_product_image_source',
- 'label' => __( 'Facebook Product Image', 'facebook-for-woocommerce' ),
- 'desc_tip' => true,
- 'description' => __( 'Choose the product image that should be synced to the Facebook catalog and displayed for this product.', 'facebook-for-woocommerce' ),
- 'options' => array(
- Products::PRODUCT_IMAGE_SOURCE_PRODUCT => __( 'Use WooCommerce image', 'facebook-for-woocommerce' ),
- Products::PRODUCT_IMAGE_SOURCE_CUSTOM => __( 'Use custom image', 'facebook-for-woocommerce' ),
- ),
- 'value' => $image_source ?: Products::PRODUCT_IMAGE_SOURCE_PRODUCT,
- 'class' => 'short enable-if-sync-enabled js-fb-product-image-source',
- 'wrapper_class' => 'fb-product-image-source-field',
- )
- );
+ woocommerce_wp_radio(
+ array(
+ 'id' => 'fb_product_image_source',
+ 'label' => __( 'Facebook Product Image', 'facebook-for-woocommerce' ),
+ 'desc_tip' => true,
+ 'description' => __( 'Choose the product image that should be synced to the Facebook catalog and displayed for this product.', 'facebook-for-woocommerce' ),
+ 'options' => array(
+ Products::PRODUCT_IMAGE_SOURCE_PRODUCT => __( 'Use WooCommerce image', 'facebook-for-woocommerce' ),
+ Products::PRODUCT_IMAGE_SOURCE_CUSTOM => __( 'Use custom image', 'facebook-for-woocommerce' ),
+ ),
+ 'value' => $image_source ? $image_source : Products::PRODUCT_IMAGE_SOURCE_PRODUCT,
+ 'class' => 'short enable-if-sync-enabled js-fb-product-image-source',
+ 'wrapper_class' => 'fb-product-image-source-field',
+ )
+ );
- woocommerce_wp_text_input(
- array(
- 'id' => \WC_Facebook_Product::FB_PRODUCT_IMAGE,
- 'label' => __( 'Custom Image URL', 'facebook-for-woocommerce' ),
- 'value' => $image,
- 'class' => sprintf( 'enable-if-sync-enabled product-image-source-field show-if-product-image-source-%s', Products::PRODUCT_IMAGE_SOURCE_CUSTOM ),
- 'desc_tip' => true,
- 'description' => __( 'Please enter an absolute URL (e.g. https://domain.com/image.jpg).', 'facebook-for-woocommerce' ),
- )
- );
+ woocommerce_wp_text_input(
+ array(
+ 'id' => \WC_Facebook_Product::FB_PRODUCT_IMAGE,
+ 'label' => __( 'Custom Image URL', 'facebook-for-woocommerce' ),
+ 'value' => $image,
+ 'class' => sprintf( 'enable-if-sync-enabled product-image-source-field show-if-product-image-source-%s', Products::PRODUCT_IMAGE_SOURCE_CUSTOM ),
+ 'desc_tip' => true,
+ 'description' => __( 'Please enter an absolute URL (e.g. https://domain.com/image.jpg).', 'facebook-for-woocommerce' ),
+ )
+ );
$this->render_facebook_product_video_field( $video_urls );
- woocommerce_wp_text_input(
- array(
- 'id' => \WC_Facebook_Product::FB_PRODUCT_PRICE,
- 'label' => sprintf(
- /* translators: Placeholders %1$s - WC currency symbol */
- __( 'Facebook Price (%1$s)', 'facebook-for-woocommerce' ),
- get_woocommerce_currency_symbol()
- ),
- 'desc_tip' => true,
- 'description' => __( 'Custom price for product on Facebook. Please enter in monetary decimal (.) format without thousand separators and currency symbols. If blank, product price will be used.', 'facebook-for-woocommerce' ),
- 'cols' => 40,
- 'rows' => 60,
- 'value' => $price,
- 'class' => 'enable-if-sync-enabled',
- )
- );
+ woocommerce_wp_text_input(
+ array(
+ 'id' => \WC_Facebook_Product::FB_PRODUCT_PRICE,
+ 'label' => sprintf(
+ /* translators: Placeholders %1$s - WC currency symbol */
+ __( 'Facebook Price (%1$s)', 'facebook-for-woocommerce' ),
+ get_woocommerce_currency_symbol()
+ ),
+ 'desc_tip' => true,
+ 'description' => __( 'Custom price for product on Facebook. Please enter in monetary decimal (.) format without thousand separators and currency symbols. If blank, product price will be used.', 'facebook-for-woocommerce' ),
+ 'cols' => 40,
+ 'rows' => 60,
+ 'value' => $price,
+ 'class' => 'enable-if-sync-enabled',
+ )
+ );
woocommerce_wp_text_input(
array(
@@ -1358,7 +1368,7 @@ public function add_product_settings_tab_content() {
'value' => '',
)
);
- ?>
+ ?>
@@ -1409,7 +1419,8 @@ public function add_product_variation_edit_fields( $index, $variation_data, $pos
}
$sync_enabled = 'no' !== $this->get_product_variation_meta( $variation, Products::SYNC_ENABLED_META_KEY, $parent );
- $is_visible = ( $visibility = $this->get_product_variation_meta( $variation, Products::VISIBILITY_META_KEY, $parent ) ) ? wc_string_to_bool( $visibility ) : true;
+ $visibility = $this->get_product_variation_meta( $variation, Products::VISIBILITY_META_KEY, $parent );
+ $is_visible = $visibility ? wc_string_to_bool( $visibility ) : true;
$description = $this->get_product_variation_meta( $variation, \WC_Facebookcommerce_Integration::FB_PRODUCT_DESCRIPTION, $parent );
$price = $this->get_product_variation_meta( $variation, \WC_Facebook_Product::FB_PRODUCT_PRICE, $parent );
$image_url = $this->get_product_variation_meta( $variation, \WC_Facebook_Product::FB_PRODUCT_IMAGE, $parent );
@@ -1440,22 +1451,22 @@ public function add_product_variation_edit_fields( $index, $variation_data, $pos
)
);
- if ($variation->get_id() && $description) {
- woocommerce_wp_textarea_input(
- array(
- 'id' => sprintf( 'variable_%s%s', \WC_Facebookcommerce_Integration::FB_PRODUCT_DESCRIPTION, $index ),
- 'name' => sprintf( "variable_%s[$index]", \WC_Facebookcommerce_Integration::FB_PRODUCT_DESCRIPTION ),
- 'label' => __( 'Facebook Description', 'facebook-for-woocommerce' ),
- 'desc_tip' => true,
- 'description' => __( 'Custom (plain-text only) description for product on Facebook. If blank, product description will be used. If product description is blank, shortname will be used.', 'facebook-for-woocommerce' ),
- 'cols' => 40,
- 'rows' => 5,
- 'value' => $description,
- 'class' => 'enable-if-sync-enabled',
- 'wrapper_class' => 'form-row form-row-full',
- )
- );
- }
+ if ( $variation->get_id() && $description ) {
+ woocommerce_wp_textarea_input(
+ array(
+ 'id' => sprintf( 'variable_%s%s', \WC_Facebookcommerce_Integration::FB_PRODUCT_DESCRIPTION, $index ),
+ 'name' => sprintf( "variable_%s[$index]", \WC_Facebookcommerce_Integration::FB_PRODUCT_DESCRIPTION ),
+ 'label' => __( 'Facebook Description', 'facebook-for-woocommerce' ),
+ 'desc_tip' => true,
+ 'description' => __( 'Custom (plain-text only) description for product on Facebook. If blank, product description will be used. If product description is blank, shortname will be used.', 'facebook-for-woocommerce' ),
+ 'cols' => 40,
+ 'rows' => 5,
+ 'value' => $description,
+ 'class' => 'enable-if-sync-enabled',
+ 'wrapper_class' => 'form-row form-row-full',
+ )
+ );
+ }
woocommerce_wp_radio(
array(
@@ -1469,7 +1480,7 @@ public function add_product_variation_edit_fields( $index, $variation_data, $pos
Products::PRODUCT_IMAGE_SOURCE_PARENT_PRODUCT => __( 'Use parent image', 'facebook-for-woocommerce' ),
Products::PRODUCT_IMAGE_SOURCE_CUSTOM => __( 'Use custom image', 'facebook-for-woocommerce' ),
),
- 'value' => $image_source ?: Products::PRODUCT_IMAGE_SOURCE_PRODUCT,
+ 'value' => $image_source ? $image_source : Products::PRODUCT_IMAGE_SOURCE_PRODUCT,
'class' => 'enable-if-sync-enabled js-fb-product-image-source',
'wrapper_class' => 'fb-product-image-source-field',
)
@@ -1526,13 +1537,13 @@ public function add_product_variation_edit_fields( $index, $variation_data, $pos
*
* @param \WC_Product_Variation $variation the product variation
* @param string $key the name of the meta to retrieve
- * @param \WC_Product $parent the parent product
+ * @param \WC_Product $parent_product the parent product
* @return mixed
*/
- private function get_product_variation_meta( $variation, $key, $parent ) {
+ private function get_product_variation_meta( $variation, $key, $parent_product ) {
$value = $variation->get_meta( $key );
- if ( '' === $value && $parent instanceof \WC_Product ) {
- $value = $parent->get_meta( $key );
+ if ( '' === $value && $parent_product instanceof \WC_Product ) {
+ $value = $parent_product->get_meta( $key );
}
return $value;
}
@@ -1553,13 +1564,13 @@ public function save_product_variation_edit_fields( $variation_id, $index ) {
if ( ! $variation instanceof \WC_Product_Variation ) {
return;
}
+ // phpcs:disable WordPress.Security.NonceVerification.Missing
$sync_mode = isset( $_POST['variable_facebook_sync_mode'][ $index ] ) ? wc_clean( wp_unslash( $_POST['variable_facebook_sync_mode'][ $index ] ) ) : self::SYNC_MODE_SYNC_DISABLED;
$sync_enabled = self::SYNC_MODE_SYNC_DISABLED !== $sync_mode;
if ( self::SYNC_MODE_SYNC_AND_SHOW === $sync_mode && $variation->is_virtual() ) {
// force to Sync and hide
$sync_mode = self::SYNC_MODE_SYNC_AND_HIDE;
}
- // phpcs:disable WordPress.Security.NonceVerification.Missing
if ( $sync_enabled ) {
Products::enable_sync_for_products( array( $variation ) );
Products::set_product_visibility( $variation, self::SYNC_MODE_SYNC_AND_HIDE !== $sync_mode );