Last active
November 22, 2022 03:23
-
-
Save simonporter007/3fb9b3d86fdc51ed1848132cfbcc0bea to your computer and use it in GitHub Desktop.
Facebook for WooCommerce: Sync inventory count along with product
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php //only copy if required! | |
/* | |
* Sync product inventory to Facebook | |
*/ | |
function sv_facebook_for_woocommerce_integration_prepare_product( $product_data, $id ) { | |
$product = wc_get_product( $id ); | |
// Get variation if variable product ID provided | |
if ( 'variable' === $product->get_type() ) { | |
if ( preg_match('/.*_(\d+)$/', $product_data[ 'retailer_id' ], $matches) ) { | |
$product = wc_get_product( $matches[1] ); | |
} | |
} | |
if ( $product ) { | |
$product_data[ 'inventory' ] = $product->get_stock_quantity(); | |
} | |
return $product_data; | |
} | |
add_filter( 'facebook_for_woocommerce_integration_prepare_product', 'sv_facebook_for_woocommerce_integration_prepare_product', 10, 2 ); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment