diff --git a/includes/Admin.php b/includes/Admin.php index 46a3f3f8e..fcd929923 100644 --- a/includes/Admin.php +++ b/includes/Admin.php @@ -1200,8 +1200,6 @@ public function add_product_settings_tab_content() { ) ); - $this->render_facebook_product_video_field( $video_urls ); - woocommerce_wp_text_input( array( 'id' => \WC_Facebook_Product::FB_PRODUCT_PRICE, @@ -1250,6 +1248,9 @@ public function add_product_settings_tab_content() { render_facebook_product_video_field( $video_urls ); + woocommerce_wp_text_input( array( 'id' => \WC_Facebook_Product::FB_MPN, diff --git a/includes/fbproduct.php b/includes/fbproduct.php index 453170bcb..118bba5ed 100644 --- a/includes/fbproduct.php +++ b/includes/fbproduct.php @@ -416,19 +416,24 @@ public function get_all_image_urls() { * * @return array */ - public function get_all_video_urls() { + public function get_all_video_urls( $parent_id = null ) { $video_urls = array(); - + $product = $this->woo_product; + + if($parent_id !== null) { + $product = wc_get_product( $parent_id ); + } + $attached_videos = get_attached_media( 'video', $this->id ); - $custom_video_urls = $this->woo_product->get_meta( self::FB_PRODUCT_VIDEO ); + $custom_video_urls = $product->get_meta( self::FB_PRODUCT_VIDEO ); if ( empty( $attached_videos ) && empty( $custom_video_urls ) ) { return $video_urls; } - // Add custom video URLs to the list + // Add custom video URLs to the list if ( ! empty( $custom_video_urls ) && is_array( $custom_video_urls ) ) { foreach ( $custom_video_urls as $custom_url ) { $custom_url = trim( $custom_url ); @@ -438,7 +443,7 @@ public function get_all_video_urls() { } } - // Add attached video URLs to the list, excluding duplicates from custom video URLs + // Add attached video URLs to the list, excluding duplicates from custom video URLs if ( ! empty( $attached_videos ) ) { $custom_video_url_set = array_flip( array_column( $video_urls, 'url' ) ); foreach ( $attached_videos as $video ) { @@ -1418,7 +1423,7 @@ private function process_attribute_values($attribute_values, $is_api_call = fals $value = $attribute_values[0]; // Clean and truncate the value directly for simple products return mb_substr(WC_Facebookcommerce_Utils::clean_string($value), 0, 200); - } + } } else { // For variable/variation products, keep all values $joined_values = implode(' | ', $attribute_values); @@ -1807,6 +1812,13 @@ public function prepare_product( $retailer_id = null, $type_to_prepare_for = sel }//end if $video_urls = $this->get_all_video_urls(); + + // If this is a variable product, get the video URLs from the parent product and add them to variations. + if($this->get_type() === "variation"){ + $parent_id = $this->woo_product->get_parent_id(); + $video_urls = $this->get_all_video_urls($parent_id); + } + if ( ! empty( $video_urls ) && self::PRODUCT_PREP_TYPE_NORMAL !== $type_to_prepare_for ) { $product_data['video'] = $video_urls; }