Skip to content

Commit

Permalink
Add rich text description to woo product sync to meta
Browse files Browse the repository at this point in the history
  • Loading branch information
David Evbodaghe committed Feb 5, 2025
1 parent 0f7fcb9 commit 8071f4f
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 24 deletions.
2 changes: 1 addition & 1 deletion facebook-commerce.php
Original file line number Diff line number Diff line change
Expand Up @@ -856,7 +856,7 @@ private function save_product_settings( WC_Product $product ) {
$woo_product->set_description( sanitize_text_field( wp_unslash( $_POST[ self::FB_PRODUCT_DESCRIPTION ] ) ) );
$woo_product->set_rich_text_description( $_POST[ self::FB_PRODUCT_DESCRIPTION ] );
}

if ( isset( $_POST[ WC_Facebook_Product::FB_PRODUCT_PRICE ] ) ) {
$woo_product->set_price( sanitize_text_field( wp_unslash( $_POST[ WC_Facebook_Product::FB_PRODUCT_PRICE ] ) ) );
}
Expand Down
34 changes: 11 additions & 23 deletions includes/fbproduct.php
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,6 @@ class WC_Facebook_Product {
const MAX_TIME = 'T23:59+00:00';
const MIN_TIME = 'T00:00+00:00';

public static $rich_text_description_source = WC_Facebookcommerce_Utils::WC_DESCRIPTION;
static $use_checkout_url = array(
'simple' => 1,
'variable' => 1,
Expand All @@ -67,11 +66,6 @@ class WC_Facebook_Product {
private $fb_description;


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

/**
* @var array Gallery URLs.
*/
Expand Down Expand Up @@ -476,9 +470,9 @@ public function get_fb_description() {
* Get the rich text description for a product.
*
* This function retrieves the rich text product description based on the following logic:
* 1. Check if the facebook rich text description is set and not empty.
* 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.
* 3. Otherwise, fall back to the plain text description made available by WooCommerce.
*
* @return string The rich text description for the product.
*/
Expand All @@ -494,16 +488,12 @@ public function 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(
$rich_text_description = get_post_meta(
$this->id,
self::FB_RICH_TEXT_DESCRIPTION,
true
);

if ( $temp_rich_text_description ) {
self::$rich_text_description_source = WC_Facebookcommerce_Utils::FB_DESCRIPTION;
$rich_text_description = $temp_rich_text_description;
}
}

// For variable products, we want to use the rich text description of the variant.
Expand Down Expand Up @@ -543,7 +533,7 @@ public function get_rich_text_description() {
*/
public function add_sale_price( $product_data, $for_items_batch = false ) {

$sale_price = $this->woo_product->get_sale_price();
$sale_price = $this->woo_product->get_sale_price();
$sale_price_effective_date = '';
$sale_start = '';
$sale_end = '';
Expand All @@ -562,7 +552,7 @@ public function add_sale_price( $product_data, $for_items_batch = false ) {
( $sale_start == self::MIN_DATE_1 . self::MIN_TIME && $sale_end == self::MAX_DATE . self::MAX_TIME )
? ''
: $sale_start . '/' . $sale_end;
$sale_price =
$sale_price =
intval( round( $this->get_price_plus_tax( $sale_price ) * 100 ) );

// Set Sale start and end as empty if set to default values
Expand Down Expand Up @@ -738,7 +728,7 @@ public function prepare_product( $retailer_id = null, $type_to_prepare_for = sel
WC_Facebookcommerce_Utils::get_product_categories( $id );

// Get brand attribute.
$brand = get_post_meta( $id, Products::ENHANCED_CATALOG_ATTRIBUTES_META_KEY_PREFIX . 'brand', true );
$brand = get_post_meta( $id, Products::ENHANCED_CATALOG_ATTRIBUTES_META_KEY_PREFIX . 'brand', true );
$brand_taxonomy = get_the_term_list( $id, 'product_brand', '', ', ' );

if ( $brand ) {
Expand All @@ -749,15 +739,14 @@ public function prepare_product( $retailer_id = null, $type_to_prepare_for = sel
$brand = wp_strip_all_tags( WC_Facebookcommerce_Utils::get_store_name() );
}

$rich_text_description = $this->get_rich_text_description();
$custom_fields = $this->get_facebook_specific_fields();

if ( self::PRODUCT_PREP_TYPE_ITEMS_BATCH === $type_to_prepare_for ) {
$product_data = array_merge(
$product_data = array(
array(
'title' => WC_Facebookcommerce_Utils::clean_string( $this->get_title() ),
'description' => $this->get_fb_description(),
'rich_text_description' => $rich_text_description,
'rich_text_description' => $this->get_rich_text_description(),
'image_link' => $image_urls[0],
'additional_image_link' => $this->get_additional_image_urls( $image_urls ),
'link' => $product_url,
Expand All @@ -767,7 +756,7 @@ public function prepare_product( $retailer_id = null, $type_to_prepare_for = sel
'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,
'custom_fields' => $custom_fields,
'custom_fields' => $custom_fields,
),
);
$product_data = $this->add_sale_price( $product_data, true );
Expand All @@ -776,14 +765,14 @@ public function prepare_product( $retailer_id = null, $type_to_prepare_for = sel
$product_data['video'] = $video_urls;
}
} else {
$product_data = array_merge(
$product_data = array(
array(
'name' => WC_Facebookcommerce_Utils::clean_string( $this->get_title() ),
'description' => $this->get_fb_description(),
'image_url' => $image_urls[0],
'additional_image_urls' => $this->get_additional_image_urls( $image_urls ),
'url' => $product_url,
'rich_text_description' => $rich_text_description,
'rich_text_description' => $this->get_rich_text_description(),
/**
* 'category' is a required field for creating a ProductItem object when posting to /{product_catalog_id}/products.
* This field should have the Google product category for the item. Google product category is not a required field
Expand Down Expand Up @@ -1175,4 +1164,3 @@ private function get_facebook_specific_fields(): array {
}

}

0 comments on commit 8071f4f

Please sign in to comment.