Search
 
SCRIPT & CODE EXAMPLE
 

PHP

updating-product stock quantity programmatically woocommerce

$out_of_stock_staus = 'outofstock';

// 1. Updating the stock quantity
update_post_meta($product_id, '_stock', 0);

// 2. Updating the stock quantity
update_post_meta( $product_id, '_stock_status', wc_clean( $out_of_stock_staus ) );

// 3. Updating post term relationship
wp_set_post_terms( $product_id, 'outofstock', 'product_visibility', true );

// And finally (optionally if needed)
wc_delete_product_transients( $product_id ); // Clear/refresh the variation cache
Comment

PREVIOUS NEXT
Code Example
Php :: date format change in laravel 
Php :: php array to string 
Php :: php remove anchor tag from string 
Php :: register_post_type wordpress 
Php :: php check if any of multiple values in array 
Php :: change datetime format from Y-m-d h:i:s to d-m-Y in php 
Php :: laravel model with methos custom columns 
Php :: php isset post 
Php :: date_sub laravel 7 
Php :: $this- attribute laravel 
Php :: separate numbers with commas laravel 
Php :: laravel model update 
Php :: log data into file php 
Php :: turn off deprecated warnings php 
Php :: get country from clouflare 
Php :: laravel access JsonResponse content 
Php :: laravel 8 get app folder 
Php :: unset session key 
Php :: php join array with comma 
Php :: php date + 30 days 
Php :: codeigniter 3 send email smtp 
Php :: change minutes in to hours carbon 
Php :: Sending Data over another website via laravel 
Php :: search function using php for database entries 
Php :: laravel duplicate row 
Php :: php if mobile 
Php :: Clear from faild_jobs laravel 
Php :: How to remove updated_at or use only created_at laravel eloquent ORM 
Php :: paystack gateway integration laravel 
Php :: php string slice 
ADD CONTENT
Topic
Content
Source link
Name
1+7 =