Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions includes/Admin.php
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -1250,6 +1248,9 @@ public function add_product_settings_tab_content() {
</script>

<?php
// Render the Facebook Product Video field at Product level
$this->render_facebook_product_video_field( $video_urls );

woocommerce_wp_text_input(
array(
'id' => \WC_Facebook_Product::FB_MPN,
Expand Down
24 changes: 18 additions & 6 deletions includes/fbproduct.php
Original file line number Diff line number Diff line change
Expand Up @@ -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 );
Expand All @@ -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 ) {
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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;
}
Expand Down