Skip to content

Instantly share code, notes, and snippets.

@webtoffee-git
Last active June 22, 2026 08:53
Show Gist options
  • Select an option

  • Save webtoffee-git/09cfb0dad60ea38221a41257fa783bd7 to your computer and use it in GitHub Desktop.

Select an option

Save webtoffee-git/09cfb0dad60ea38221a41257fa783bd7 to your computer and use it in GitHub Desktop.
WebToffee Facebook Feed: Fix missing video tag from Meta for WooCommerce - By WebToffee(WebToffee WooCommerce Product Feeds – Google Shopping, Pinterest, TikTok Ads, & More)
<?php //Do not copy this line of code
add_filter( 'wt_batch_product_export_row_data_facebook', 'wt_fix_facebook_video_field', 10, 2 );
function wt_fix_facebook_video_field( $row, $product ) {
// Only run if the feed actually has a 'video' column mapped
if ( ! array_key_exists( 'video', $row ) ) {
return $row;
}
$product_id = $product->get_id();
// Read the meta value. Meta for WooCommerce stores it as an array of URLs,
// e.g. [ 'https://yoursite.com/wp-content/uploads/video.mp4' ]
$video_urls = get_post_meta( $product_id, 'fb_product_video', true );
// If the variation itself has no video, fall back to the parent product
if ( empty( $video_urls ) && $product->is_type( 'variation' ) ) {
$video_urls = get_post_meta( $product->get_parent_id(), 'fb_product_video', true );
}
if ( ! empty( $video_urls ) && is_array( $video_urls ) ) {
// Use the first video URL in the list
$first_url = reset( $video_urls );
if ( ! empty( $first_url ) && filter_var( $first_url, FILTER_VALIDATE_URL ) ) {
$row['video'] = esc_url_raw( $first_url );
}
}
return $row;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment