Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
WordPress action to sync stock quantity to connected sites with the WooCommerce Stock Synchronization plugin when using WP All Import to update stock on the master shop.
<?php
// Add below code to functions.php of your WordPress theme.
/**
* Sync stock with WooCommerce Stock Synchronization after WP All Import product update.
*
* @see https://www.pronamic.eu/plugins/woocommerce-stock-synchronization/
*/
function wcss_pmxi_stock_update( $post_id ) {
if ( ! is_callable( 'wc_get_product' ) ) {
return;
}
$product = wc_get_product( $post_id );
if ( ! $product ) {
return;
}
if ( $product->is_type( 'variation' ) ) {
do_action( 'woocommerce_variation_set_stock', $product );
} else {
do_action( 'woocommerce_product_set_stock', $product );
}
}
add_action( 'pmxi_saved_post', 'wcss_pmxi_stock_update', 10, 1 );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.