Skip to content

Instantly share code, notes, and snippets.

@lukecav
Created May 10, 2023 21:29
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 lukecav/b7a83c39d1577c3b8b8bcdbb1fa12b45 to your computer and use it in GitHub Desktop.
Save lukecav/b7a83c39d1577c3b8b8bcdbb1fa12b45 to your computer and use it in GitHub Desktop.
Change product tag on stock change in WooCommerce
function action_woocommerce_low_stock( $wc_get_product ) {
// Product set tag id(s), multiple IDs can be added, separated by a comma
$wc_get_product->set_tag_ids( array( 'YOUR TAG ID' ) );
// OPTIONAL: Set category ids
//$wc_get_product->set_category_ids( array( 39, 2 ) );
// Save
$wc_get_product->save();
}
add_action( 'woocommerce_low_stock', 'action_woocommerce_low_stock', 10, 1 );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment