Created
October 12, 2021 18:09
-
-
Save bob-moore/192e0b729d869897521963a5b6cbed04 to your computer and use it in GitHub Desktop.
This file contains hidden or 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 | |
function generate_price_metadata( $product_id ) { | |
/** | |
* Get the product based on ID | |
*/ | |
$product = wc_get_product( $product_id ); | |
/** | |
* This should be set during import to false | |
* | |
* Correcting this setting here for variable products so stock is managed | |
* at the variation level, not at the product level | |
*/ | |
update_post_meta( $product_id, '_manage_stock', false ); | |
/** | |
* Method only exists for variable products, so double check in case of | |
* simple product | |
* | |
* Runs the sync function to generate the '_price' metadata | |
*/ | |
if ( method_exists( $product, 'sync' ) ) { | |
$product::sync( $product ); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment