Created
February 18, 2020 07:17
-
-
Save vmanthos/8f22925ae2fbcebbd48aa5abf453ff74 to your computer and use it in GitHub Desktop.
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 | |
require( 'wp-load.php' ); | |
define('WP_USE_THEMES', false); | |
$sku = 'wp-pennant'; | |
// get the product ID from the SKU | |
$product_id = $wpdb->get_var( $wpdb->prepare( "SELECT post_id FROM $wpdb->postmeta WHERE meta_key='_sku' AND meta_value='%s' LIMIT 1", $sku ) ); | |
// Get an instance of the WC_Product object | |
$product = new WC_Product( $product_id ); | |
// Get product stock quantity and stock status | |
$stock_quantity = $product->get_stock_quantity(); | |
$stock_status = $product->get_stock_status(); | |
// Display stock quantity and status | |
echo '<p>Product Stock quantity: ' . $stock_quantity; | |
// Set product stock quantity | |
$product->set_stock_quantity( 3 ); | |
// Save the data/clear caches | |
$product->save(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment