Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save alexmigf/384633c5cdb12c6444fce69b29a15e97 to your computer and use it in GitHub Desktop.
Save alexmigf/384633c5cdb12c6444fce69b29a15e97 to your computer and use it in GitHub Desktop.
Update product _stock meta with locations stock on WP All Import
<?php
add_action( 'pmxi_saved_post', function( $id )
{
// get locations total stock
$locations_total_stock = \SLW\SRC\Helpers\SlwProductHelper::get_product_locations_stock_total( $id );
// update stock
update_post_meta( $id, '_stock', $locations_total_stock );
// update stock status
\SLW\SRC\Helpers\SlwProductHelper::update_wc_stock_status( $id );
}, 10, 1 );
@alexmigf
Copy link
Author

Instructions:

  1. Install the Code Snippets plugin: https://wordpress.org/plugins/code-snippets/
  2. Create a new snippet in the Code Snippets plugin and paste the code above without the <?php

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment