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

Product with ALL CAPS name isn't synced with Facebook #2582

Closed
2 tasks done
krutidugade opened this issue Jul 17, 2023 · 4 comments · Fixed by #2589
Closed
2 tasks done

Product with ALL CAPS name isn't synced with Facebook #2582

krutidugade opened this issue Jul 17, 2023 · 4 comments · Fixed by #2589
Assignees
Labels
priority: low The issue/PR is low priority—not many people are affected or there’s a workaround, etc. type: enhancement The issue is a request for an enhancement.

Comments

@krutidugade
Copy link
Contributor

krutidugade commented Jul 17, 2023

🔎 Isolate the bug

  • I have confirmed this occurs in the most recent version of WordPress, WooCommerce, and Facebook for WooCommerce.
  • I have confirmed this occurs when only WooCommerce and Facebook for WooCommerce are active and when using a default WordPress or WooCommerce theme.

✍️ Describe the bug

The product isn't synced to Facebook if the product name is in All CAPS. Facebook has specified guidelines for avoiding product names with all caps but it isn't a rule. The existing behavior isn't necessarily unexpected but we would want to sync the product and show a warning instead.

🚶‍♀️ Steps to reproduce

  1. Install and activate Facebook for WooCommerce plugin
  2. Go to Products > Add New
  3. Add product name in caps "SHIRT" and update
  4. Go to Marketing > Facebook > Product Sync
  5. Click Sync products

✔️ Actual behavior

The newly created product won't appear in the Facebook catalog. You can see "Do not sync" beside these products on the All Products page.

✔️ Expected behavior

The product should be synced to the Facebook catalog. Also, we would want a warning stating Facebook's guideline of not setting product names in all caps.

@krutidugade krutidugade added priority: low The issue/PR is low priority—not many people are affected or there’s a workaround, etc. type: enhancement The issue is a request for an enhancement. labels Jul 17, 2023
@krutidugade krutidugade self-assigned this Jul 17, 2023
@krutidugade
Copy link
Contributor Author

krutidugade commented Jul 18, 2023

The plugin checks if the product description or product name is in ALL CAPS. If yes then it doesn't sync those products with FB. We want to change this behavior. We want the products to sync and show a warning or notice informing user about Facebook's ALL CAPS guideline.

I searched for "product sync" in the repo and found ProductValidator.php file has validation functions for product description and product name.

  • validate_product_title() and validate_product_description() functions throw ProductInvalidException exception if the product name or description doesn't meet the requirement which is ALL CAPS. (that's our focus)
  • If you comment out
    throw new ProductInvalidException( __( 'Product description is all capital letters. Please change the description to sentence case in order to allow synchronization of your product.', 'facebook-for-woocommerce' ) );
    and
    throw new ProductInvalidException( __( 'Product title is all capital letters. Please change the title to sentence case in order to allow synchronization of your product.', 'facebook-for-woocommerce' ) );
    then the products with all caps description or title are synced.
  • Next, we would want to show a warning to the user

Here's my approach:

  1. Call validate function on publishing new product or updating an existing product (hunch: transition_post_status or woocommerce_update_product)
  2. Remove ProductInvalidException code from validate functions.
  3. Call another function if ALL CAPS condition is true
  4. Other function displays a notice or warning

@krutidugade
Copy link
Contributor Author

Remove ProductInvalidException code from validate functions.
Call another function if ALL CAPS condition is true

I was going to call the existing validate() function and make a call to a custom function that shows notice if ALL CAPS condition is true. However, this doesn't seem good approach as my custom function will be called everytime validate() is called. This would mean every time code wants to check if a FB product should be synced, my custom function will show a notice. So I have changed my approach slightly.

  1. Call custom function on publishing new product or updating existing product (Using woocommerce_update_product and woocommerce_new_product hooks)
  2. Call validate function from a custom function
  3. Remove ProductInvalidException code from validate functions.
  4. Have validate function return a boolean value
  5. If the value is true then display a warning in a modal window
  • Call validate function from a custom function
  • Remove ProductInvalidException code from validate functions.
  • Have validate function return a boolean value

I noticed a downside to this approach as well. There are a bunch of validation functions along with validate_product_description() and validate_product_title() within validate() function. My focus is on product title and description. So why call other validation functions? I wrote a custom validation function and called validate_product_description() and validate_product_title(). In order to return a value I would have to alter the existing function. It wouldn't harm to change these functions but I felt it is better to write a custom validation function altogether. I removed all caps validation from existing functions and wrote a simple function that returns a boolean value.

public function validate_all_caps(): bool {
		return \WC_Facebookcommerce_Utils::is_all_caps( $this->product->get_name() ) || \WC_Facebookcommerce_Utils::is_all_caps( $this->facebook_product->get_fb_description() );
	}
  1. Call a custom show notice function on publishing new product or updating existing product (Using woocommerce_update_product and woocommerce_new_product hooks)
  2. Call a custom all caps validation function from the show notice function
  3. Have all caps validation function return a boolean value
  4. If the value is true then display a warning in a modal window

I'll give it some more thought if I want a separate all caps validation function or just do all caps check in the same function. I'm yet to figure out how to show pop-up modal window for notice.

@krutidugade
Copy link
Contributor Author

Facebook recommends sentence case and not ALL CAPS for product titles. However, it is still a requirement (not just a guideline) for product description.

Altering this issue to focus on removing validation for product titles only.

@krutidugade krutidugade changed the title Product with ALL CAPS name and/or description isn't synced with Facebook Product with ALL CAPS name isn't synced with Facebook Jul 20, 2023
@krutidugade
Copy link
Contributor Author

We have decided to show the warning in the Facebook panel (bottom right corner) on the product edit page instead of a modal window. So we no longer need woocommerce_update_product and woocommerce_new_product hooks.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
priority: low The issue/PR is low priority—not many people are affected or there’s a workaround, etc. type: enhancement The issue is a request for an enhancement.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant