Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add rich text description to woo product sync to meta #2843

Open
wants to merge 21 commits into
base: main
Choose a base branch
from

Conversation

devbodaghe
Copy link
Contributor

Add Rich Text Description to Woo Product Sync with Meta

Description

This PR introduces a new feature to the Facebook WooCommerce Plugin, allowing users to add rich text descriptions to their products. With this update, we can seamlessly synchronize the rich text description field with the Facebook Commerce Manager platform.

It also adds functionality for a WYSIWYG input box for the Facebook Description field in the plugin

Changes

  • Updated the product sync logic to handle rich text formatting.
  • Modified the API payload to include the rich text description field.
  • Tested for compatibility with common formatting options (bold, italic, lists, links, etc.).

Benefits

  • Improves the visual appeal of product descriptions on Meta.
  • Ensures consistent branding and formatting across platforms.
  • Enhances user engagement by presenting more structured and detailed product information.

Testing Instructions

  1. Enable the WooCommerce to Meta product sync.
  2. Create or edit a product in WooCommerce with a rich text description (e.g., headings, bold, italic, lists).
  3. Sync the product and verify that the description appears correctly formatted on Meta.

Screenshots

Screenshot 2024-11-04 at 11 21 23 Screenshot 2024-11-04 at 11 22 26 Screenshot 2024-11-04 at 11 22 41 Screenshot 2024-12-24 at 18 24 52

Additional Notes

Please let me know if there are any edge cases or scenarios that should be tested further.

@devbodaghe devbodaghe marked this pull request as ready for review December 24, 2024 18:26
@devbodaghe devbodaghe changed the title Add rtd to woo product sync to meta Add rich text description to woo product sync to meta Jan 7, 2025
@devbodaghe devbodaghe force-pushed the add_rtd_to_woo_product_sync_to_meta branch from 789f936 to 0029291 Compare January 22, 2025 00:11
facebook-commerce.php Show resolved Hide resolved
@@ -1468,6 +1461,7 @@ public function save_product_variation_edit_fields( $variation_id, $index ) {
Products::set_product_visibility( $variation, self::SYNC_MODE_SYNC_AND_HIDE !== $sync_mode );
$posted_param = 'variable_' . \WC_Facebookcommerce_Integration::FB_PRODUCT_DESCRIPTION;
$description = isset( $_POST[ $posted_param ][ $index ] ) ? sanitize_text_field( wp_unslash( $_POST[ $posted_param ][ $index ] ) ) : null;
$posted_param = 'variable_' . \WC_Facebookcommerce_Integration::FB_RICH_TEXT_DESCRIPTION;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Isn't this going to be overridden in the next line?

/**
* @var string Facebook Rich Text Description.
*/
private $fb_rich_text_description;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This does not seem to be used later

Comment on lines 479 to 481
* 1. Check if the facebook rich text description is set and not empty.
* 2. If the rich text description is available, use it as the preferred description.
* 3. Otherwise, fall back to the plain text description made available by Woocommerce.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
* 1. Check if the facebook rich text description is set and not empty.
* 2. If the rich text description is available, use it as the preferred description.
* 3. Otherwise, fall back to the plain text description made available by Woocommerce.
* 1. Check if the Facebook rich text description is set and not empty.
* 2. If the rich text description is available, use it as the preferred description.
* 3. Otherwise, fall back to the plain text description made available by WooCommerce.

array(
'title' => WC_Facebookcommerce_Utils::clean_string( $this->get_title() ),
'description' => $this->get_fb_description(),
'rich_text_description' => $rich_text_description,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No need for extra variable

Suggested change
'rich_text_description' => $rich_text_description,
'rich_text_description' => $this->get_rich_text_description(),


// Try to get rich text description from post meta if description has been set
if ( empty( $rich_text_description ) ) {
$temp_rich_text_description = get_post_meta(
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks like $temp_rich_text_description is not necessary, you can just use $rich_text_description.

'price' => $this->get_fb_price( true ),
'availability' => $this->is_in_stock() ? 'in stock' : 'out of stock',
'visibility' => Products::is_product_visible( $this->woo_product ) ? \WC_Facebookcommerce_Integration::FB_SHOP_PRODUCT_VISIBLE : \WC_Facebookcommerce_Integration::FB_SHOP_PRODUCT_HIDDEN,
$product_data = array_merge(
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What arrays are you merging here? Looks like there is only 1 array.

@@ -555,7 +554,6 @@ public function test_on_product_save_existing_simple_product_sync_enabled_update

$facebook_product_to_update = new WC_Facebook_Product( $product_to_update->get_id() );

$this->assertEquals( 'Facebook product description.', get_post_meta( $facebook_product_to_update->get_id(), WC_Facebook_Product::FB_PRODUCT_DESCRIPTION, true ) );
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why do we not need this assert anymore?

@devbodaghe devbodaghe force-pushed the add_rtd_to_woo_product_sync_to_meta branch 2 times, most recently from 426371c to 0f7fcb9 Compare February 5, 2025 19:46
@facebook-github-bot
Copy link
Contributor

@devbodaghe has imported this pull request. If you are a Meta employee, you can view this diff on Phabricator.

2 similar comments
@facebook-github-bot
Copy link
Contributor

@devbodaghe has imported this pull request. If you are a Meta employee, you can view this diff on Phabricator.

@facebook-github-bot
Copy link
Contributor

@devbodaghe has imported this pull request. If you are a Meta employee, you can view this diff on Phabricator.

@devbodaghe devbodaghe force-pushed the add_rtd_to_woo_product_sync_to_meta branch from 04b8d80 to 09791ad Compare February 7, 2025 15:05
@facebook-github-bot
Copy link
Contributor

@devbodaghe has updated the pull request. You must reimport the pull request before landing.

@facebook-github-bot
Copy link
Contributor

@devbodaghe has imported this pull request. If you are a Meta employee, you can view this diff on Phabricator.

@facebook-github-bot
Copy link
Contributor

@devbodaghe has updated the pull request. You must reimport the pull request before landing.

@facebook-github-bot
Copy link
Contributor

@devbodaghe has imported this pull request. If you are a Meta employee, you can view this diff on Phabricator.

@devbodaghe devbodaghe force-pushed the add_rtd_to_woo_product_sync_to_meta branch from bc81474 to ca0c1a4 Compare February 11, 2025 13:44
@facebook-github-bot
Copy link
Contributor

@devbodaghe has updated the pull request. You must reimport the pull request before landing.

@facebook-github-bot
Copy link
Contributor

@devbodaghe has imported this pull request. If you are a Meta employee, you can view this diff on Phabricator.

@facebook-github-bot
Copy link
Contributor

@devbodaghe has updated the pull request. You must reimport the pull request before landing.

@facebook-github-bot
Copy link
Contributor

@devbodaghe has imported this pull request. If you are a Meta employee, you can view this diff on Phabricator.

@devbodaghe devbodaghe force-pushed the add_rtd_to_woo_product_sync_to_meta branch from bd71a64 to 3fb2156 Compare February 11, 2025 15:21
@facebook-github-bot
Copy link
Contributor

@devbodaghe has updated the pull request. You must reimport the pull request before landing.

@facebook-github-bot
Copy link
Contributor

@devbodaghe has imported this pull request. If you are a Meta employee, you can view this diff on Phabricator.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants