To link a WordPress website with a Facebook Catalog (Commerce Manager) without using the official Facebook for WooCommerce plugin, you can do this manually using Facebook’s Catalog Feed (Data Feed) system. Essentially, you need to:
🛠️ 1. Generate Product Feed Programmatically
To isolate the feed logic and avoid whitespace issues, you can place your feed function in a simple plugin file:
Step-by-step:
Go to /wp-content/plugins/.
Create a file called facebook-product-feed.php.
Add the following clean code:
add_action('init', 'custom_facebook_product_feed');
function custom_facebook_product_feed() {
if (isset($_GET['facebook_feed']) && $_GET['facebook_feed'] == '1') {
header('Content-Type: application/xml; charset=utf-8');
$products = wc_get_products(['limit' => -1]);
echo '<?xml version="1.0" encoding="UTF-8"?>';
echo '<rss version="2.0" xmlns:g="http://base.google.com/ns/1.0">';
echo '<channel>';
echo '<title>' . htmlspecialchars(get_bloginfo('name')) . '</title>';
echo '<link>' . htmlspecialchars(home_url()) . '</link>';
echo '<description>Facebook Product Feed</description>';
foreach ($products as $product) {
echo '<item>';
echo '<g:id>' . htmlspecialchars($product->get_id()) . '</g:id>';
echo '<title>' . htmlspecialchars($product->get_name()) . '</title>';
echo '<description>' . htmlspecialchars(strip_tags($product->get_description())) . '</description>';
echo '<link>' . htmlspecialchars(get_permalink($product->get_id())) . '</link>';
echo '<g:image_link>' . htmlspecialchars(wp_get_attachment_url($product->get_image_id())) . '</g:image_link>';
echo '<g:price>' . htmlspecialchars($product->get_price()) . ' ' . htmlspecialchars(get_woocommerce_currency()) . '</g:price>';
echo '<g:availability>' . ($product->is_in_stock() ? 'in stock' : 'out of stock') . '</g:availability>';
echo '</item>';
}
echo '</channel>';
echo '</rss>';
exit;
}
}
📤 2. Add Feed to Facebook Catalog
Go to Facebook Commerce Manager.
Choose your catalog > Data Sources > Data Feeds.
Click Add Products > Use Data Feed.
Enter the feed URL (https://yourdomain.com/?facebook_feed=1).
Schedule updates (e.g., daily).
🔄 3. Automate Feed Refresh
Facebook can automatically fetch updates on a schedule (daily, weekly, hourly). Make sure your feed URL stays accessible and up to date.