WC_Predictive_Search_Synch

The WooCommerce Predictive Search LITE WC Predictive Search Synch class.

Defined (1)

The class is defined in the following location(s).

/classes/class-wc-predictive-search-synch.php  
  1. class WC_Predictive_Search_Synch 
  2. public function __construct() { 
  3.  
  4. // Synch for post 
  5. add_action( 'init', array( $this, 'sync_process_post' ), 1 ); 
  6.  
  7. add_action( 'admin_notices', array( $this, 'start_sync_data_notice' ), 11 ); 
  8.  
  9. /** 
  10. * Synch for custom mysql query from 3rd party plugin 
  11. * Call below code on 3rd party plugin when create post by mysql query 
  12. * do_action( 'mysql_inserted_post', $post_id ); 
  13. */ 
  14. add_action( 'mysql_inserted_post', array( $this, 'synch_mysql_inserted_post' ) ); 
  15.  
  16. if ( is_admin() ) { 
  17. // AJAX sync data 
  18. add_action('wp_ajax_wc_predictive_search_sync_products', array( $this, 'wc_predictive_search_sync_products_ajax' ) ); 
  19. add_action('wp_ajax_nopriv_wc_predictive_search_sync_products', array( $this, 'wc_predictive_search_sync_products_ajax' ) ); 
  20.  
  21. add_action('wp_ajax_wc_predictive_search_sync_product_skus', array( $this, 'wc_predictive_search_sync_product_skus_ajax' ) ); 
  22. add_action('wp_ajax_nopriv_wc_predictive_search_sync_product_skus', array( $this, 'wc_predictive_search_sync_product_skus_ajax' ) ); 
  23.  
  24. add_action('wp_ajax_wc_predictive_search_sync_categories', array( $this, 'wc_predictive_search_sync_categories_ajax' ) ); 
  25. add_action('wp_ajax_nopriv_wc_predictive_search_sync_categories', array( $this, 'wc_predictive_search_sync_categories_ajax' ) ); 
  26.  
  27. add_action('wp_ajax_wc_predictive_search_sync_tags', array( $this, 'wc_predictive_search_sync_tags_ajax' ) ); 
  28. add_action('wp_ajax_nopriv_wc_predictive_search_sync_tags', array( $this, 'wc_predictive_search_sync_tags_ajax' ) ); 
  29.  
  30. add_action('wp_ajax_wc_predictive_search_sync_relationships', array( $this, 'wc_predictive_search_sync_relationships_ajax' ) ); 
  31. add_action('wp_ajax_nopriv_wc_predictive_search_sync_relationships', array( $this, 'wc_predictive_search_sync_relationships_ajax' ) ); 
  32.  
  33. add_action('wp_ajax_wc_predictive_search_sync_posts', array( $this, 'wc_predictive_search_sync_posts_ajax' ) ); 
  34. add_action('wp_ajax_nopriv_wc_predictive_search_sync_posts', array( $this, 'wc_predictive_search_sync_posts_ajax' ) ); 
  35.  
  36. add_action('wp_ajax_wc_predictive_search_sync_pages', array( $this, 'wc_predictive_search_sync_pages_ajax' ) ); 
  37. add_action('wp_ajax_nopriv_wc_predictive_search_sync_pages', array( $this, 'wc_predictive_search_sync_pages_ajax' ) ); 
  38.  
  39. add_action('wp_ajax_wc_predictive_search_sync_end', array( $this, 'wc_predictive_search_sync_end_ajax' ) ); 
  40. add_action('wp_ajax_nopriv_wc_predictive_search_sync_end', array( $this, 'wc_predictive_search_sync_end_ajax' ) ); 
  41.  
  42. public function start_sync_data_notice() { 
  43. $had_sync_posts_data = get_option( 'wc_predictive_search_had_sync_posts_data', 0 ); 
  44. $is_upgraded_new_sync_data = get_option( 'wc_ps_upgraded_to_new_sync_data', 0 ); 
  45.  
  46. if ( 0 != $had_sync_posts_data && 0 != $is_upgraded_new_sync_data ) return; 
  47.  
  48. if ( 0 == $is_upgraded_new_sync_data ) { 
  49. $heading_text = __( 'Thanks for upgrading to latest version of WooCommerce Predictive Search' , 'woocommerce-predictive-search' ); 
  50. $warning_text = __( 'The setup is almost done. Just one more step and you are ready to go. Please run database Sync to populate your Search engine database.' , 'woocommerce-predictive-search' ); 
  51. } else { 
  52. $heading_text = __( 'Thanks for installing WooCommerce Predictive Search' , 'woocommerce-predictive-search' ); 
  53. $warning_text = __( 'The setup is almost done. Just one more step and you are ready to go. Please run database Sync to populate your Search engine database.' , 'woocommerce-predictive-search' ); 
  54.  
  55. $warning_text = __( 'The setup is almost done. Just one more step and you are ready to go. Please run database Sync to populate your Search engine database.' , 'woocommerce-predictive-search' ); 
  56.  
  57. $sync_data_url = admin_url( 'admin.php?page=woo-predictive-search&tab=performance-settings&box_open=predictive_search_synch_data#predictive_search_synch_data', 'relative' ); 
  58. ?> 
  59. <div class="message error wc_ps_sync_data_warning"> 
  60. <p> 
  61. <strong><?php echo $heading_text; ?></strong> 
  62. - <?php echo $warning_text; ?> 
  63. </p> 
  64. <p> 
  65. <a class="button button-primary" href="<?php echo $sync_data_url; ?>" target="_parent"><?php echo __( 'Sync Now' , 'woocommerce-predictive-search' ); ?></a> 
  66. </p> 
  67. </div> 
  68. <?php 
  69.  
  70. public function wc_predictive_search_sync_products_ajax() { 
  71. $status = 'completed'; 
  72. $end_time = time() + 16; 
  73.  
  74. $this->migrate_posts( 'product', $end_time ); 
  75.  
  76. global $wc_ps_posts_data; 
  77. $current_products = $wc_ps_posts_data->get_total_items_synched( 'product' ); 
  78.  
  79. $all_products = wp_count_posts( 'product' ); 
  80. $total_products = isset( $all_products->publish ) ? $all_products->publish : 0; 
  81.  
  82. if ( $total_products > $current_products ) { 
  83. $status = 'continue'; 
  84.  
  85. echo json_encode( array( 'status' => $status, 'current_items' => $current_products, 'total_items' => $total_products ) ); 
  86.  
  87. die(); 
  88.  
  89. public function wc_predictive_search_sync_product_skus_ajax() { 
  90. $status = 'completed'; 
  91. $end_time = time() + 16; 
  92.  
  93. $this->migrate_skus( $end_time ); 
  94.  
  95. global $wc_ps_product_sku_data; 
  96. $current_skus = $wc_ps_product_sku_data->get_total_items_synched(); 
  97.  
  98. $total_skus = $wc_ps_product_sku_data->get_total_items_need_sync(); 
  99. $total_skus = ! empty( $total_skus ) ? $total_skus : 0; 
  100.  
  101. if ( $total_skus > $current_skus ) { 
  102. $status = 'continue'; 
  103.  
  104. echo json_encode( array( 'status' => $status, 'current_items' => $current_skus, 'total_items' => $total_skus ) ); 
  105.  
  106. die(); 
  107.  
  108. public function wc_predictive_search_sync_categories_ajax() { 
  109. $status = 'completed'; 
  110.  
  111. echo json_encode( array( 'status' => $status, 'current_items' => 0, 'total_items' => 0 ) ); 
  112.  
  113. die(); 
  114.  
  115. public function wc_predictive_search_sync_tags_ajax() { 
  116. $status = 'completed'; 
  117.  
  118. echo json_encode( array( 'status' => $status, 'current_items' => 0, 'total_items' => 0 ) ); 
  119.  
  120. die(); 
  121.  
  122. public function wc_predictive_search_sync_relationships_ajax() { 
  123. $status = 'completed'; 
  124.  
  125. echo json_encode( array( 'status' => $status, 'current_items' => 0, 'total_items' => 0 ) ); 
  126.  
  127. die(); 
  128.  
  129. public function wc_predictive_search_sync_posts_ajax() { 
  130. $status = 'completed'; 
  131. $end_time = time() + 16; 
  132.  
  133. $this->migrate_posts( 'post', $end_time ); 
  134.  
  135. global $wc_ps_posts_data; 
  136. $current_posts = $wc_ps_posts_data->get_total_items_synched( 'post' ); 
  137.  
  138. $all_posts = wp_count_posts( 'post' ); 
  139. $total_posts = isset( $all_posts->publish ) ? $all_posts->publish : 0; 
  140.  
  141. if ( $total_posts > $current_posts ) { 
  142. $status = 'continue'; 
  143.  
  144. echo json_encode( array( 'status' => $status, 'current_items' => $current_posts, 'total_items' => $total_posts ) ); 
  145.  
  146. die(); 
  147.  
  148. public function wc_predictive_search_sync_pages_ajax() { 
  149. $status = 'completed'; 
  150. $end_time = time() + 16; 
  151.  
  152. $this->migrate_posts( 'page', $end_time ); 
  153.  
  154. global $wc_ps_posts_data; 
  155. $current_pages = $wc_ps_posts_data->get_total_items_synched( 'page' ); 
  156.  
  157. $all_pages = wp_count_posts( 'page' ); 
  158. $total_pages = isset( $all_pages->publish ) ? $all_pages->publish : 0; 
  159.  
  160. if ( $total_pages > $current_pages ) { 
  161. $status = 'continue'; 
  162.  
  163. echo json_encode( array( 'status' => $status, 'current_items' => $current_pages, 'total_items' => $total_pages ) ); 
  164.  
  165. die(); 
  166.  
  167. public function wc_predictive_search_sync_end_ajax() { 
  168. update_option( 'wc_predictive_search_synced_posts_data', 1 ); 
  169.  
  170. echo json_encode( array( 'status' => 'OK' ) ); 
  171.  
  172. die(); 
  173.  
  174. public function sync_process_post() { 
  175. add_action( 'save_post', array( $this, 'synch_save_post' ), 12, 2 ); 
  176. add_action( 'delete_post', array( $this, 'synch_delete_post' ) ); 
  177.  
  178. public function empty_posts() { 
  179. global $wc_ps_posts_data; 
  180. global $wc_ps_postmeta_data; 
  181. global $wc_ps_product_sku_data; 
  182.  
  183. // Empty all tables 
  184. $wc_ps_posts_data->empty_table(); 
  185. $wc_ps_postmeta_data->empty_table(); 
  186. $wc_ps_product_sku_data->empty_table(); 
  187.  
  188. update_option( 'wc_predictive_search_synced_posts_data', 0 ); 
  189.  
  190. public function update_sync_status() { 
  191. update_option( 'wc_predictive_search_had_sync_posts_data', 1 ); 
  192. update_option( 'wc_ps_upgraded_to_new_sync_data', 1 ); 
  193.  
  194. public function migrate_posts( $post_types = array( 'product' ), $end_time = 0 ) { 
  195. global $wpdb; 
  196. global $wc_ps_posts_data; 
  197. global $wc_ps_postmeta_data; 
  198.  
  199. $this->update_sync_status(); 
  200.  
  201. if ( ! is_array( $post_types ) ) { 
  202. $post_types = array( $post_types ); 
  203. $post_types = apply_filters( 'predictive_search_post_types_support', $post_types ); 
  204.  
  205. // Check if synch data is stopped at latest run then continue synch without empty all the tables 
  206. $synced_data = get_option( 'wc_predictive_search_synced_posts_data', 0 ); 
  207.  
  208. if ( 0 == $synced_data ) { 
  209. // continue synch data from stopped post ID 
  210. $stopped_ID = $wc_ps_posts_data->get_latest_post_id( $post_types ); 
  211. if ( empty( $stopped_ID ) || is_null( $stopped_ID ) ) { 
  212. $stopped_ID = 0; 
  213. } else { 
  214. $this->empty_posts(); 
  215. $stopped_ID = 0; 
  216.  
  217. // If it's newest ID then fetch missed old ID to sync 
  218. if ( $wc_ps_posts_data->is_newest_id( $post_types ) ) { 
  219. $all_posts = $wpdb->get_results( 
  220. $wpdb->prepare( 
  221. "SELECT p.ID, p.post_title, p.post_type FROM {$wpdb->posts} AS p WHERE p.post_status = %s AND p.post_type IN ('". implode("', '", $post_types ) ."') AND NOT EXISTS ( SELECT 1 FROM {$wpdb->ps_posts} AS pp WHERE p.ID = pp.post_id ) ORDER BY p.ID ASC LIMIT 0, 500" ,  
  222. 'publish' 
  223. ); 
  224.  
  225. // Or continue sync based latest ID have synced 
  226. } else { 
  227. $all_posts = $wpdb->get_results( 
  228. $wpdb->prepare( 
  229. "SELECT p.ID, p.post_title, p.post_type FROM {$wpdb->posts} AS p WHERE p.ID > %d AND p.post_status = %s AND p.post_type IN ('". implode("', '", $post_types ) ."') ORDER BY p.ID ASC LIMIT 0, 500" ,  
  230. $stopped_ID,  
  231. 'publish' 
  232. ); 
  233.  
  234. if ( $all_posts && is_array( $all_posts ) && count( $all_posts ) > 0 ) { 
  235.  
  236. foreach ( $all_posts as $item ) { 
  237.  
  238. // Stop command after timeout is set 
  239. if ( $end_time > 0 && $end_time <= time() ) { 
  240. break; 
  241.  
  242. $post_id = $item->ID; 
  243.  
  244. $item_existed = $wc_ps_posts_data->is_item_existed( $post_id ); 
  245. if ( '0' == $item_existed ) { 
  246. $post_title = $item->post_title; 
  247. if ( in_array( $item->post_type, array( 'product_variation' ) ) ) { 
  248. $post_title = WC_Predictive_Search_Functions::get_product_variation_name( $post_id ); 
  249. $wc_ps_posts_data->insert_item( $post_id, $post_title, $item->post_type ); 
  250.  
  251. public function migrate_skus( $end_time = 0 ) { 
  252. global $wpdb; 
  253. global $wc_ps_postmeta_data; 
  254. global $wc_ps_product_sku_data; 
  255.  
  256. $this->update_sync_status(); 
  257.  
  258. // Check if synch data is stopped at latest run then continue synch without empty all the tables 
  259. $synced_data = get_option( 'wc_predictive_search_synced_posts_data', 0 ); 
  260.  
  261. if ( 0 == $synced_data ) { 
  262. // continue synch data from stopped post ID 
  263. $stopped_ID = $wc_ps_product_sku_data->get_latest_post_id(); 
  264. if ( empty( $stopped_ID ) || is_null( $stopped_ID ) ) { 
  265. $stopped_ID = 0; 
  266. } else { 
  267. $wc_ps_product_sku_data->empty_table(); 
  268. $stopped_ID = 0; 
  269.  
  270. /**$all_skus = $wpdb->get_results( 
  271. $wpdb->prepare( 
  272. "SELECT p.ID, p.post_parent, pm.meta_value FROM {$wpdb->posts} AS p INNER JOIN {$wpdb->postmeta} AS pm ON (p.ID=pm.post_id) WHERE p.ID > %d AND p.post_type IN ('". implode("', '", array( 'product', 'product_variation' ) ) ."') AND p.post_status = %s AND pm.meta_key = %s AND pm.meta_value NOT LIKE '' ORDER BY p.ID ASC LIMIT 0, 500",  
  273. $stopped_ID,  
  274. 'publish',  
  275. '_sku' 
  276. );*/ 
  277.  
  278. // If it's newest ID then fetch missed old ID to sync 
  279. if ( $wc_ps_product_sku_data->is_newest_id() ) { 
  280. $all_skus = $wpdb->get_results( 
  281. $wpdb->prepare( 
  282. "SELECT p.ID, p.post_parent FROM {$wpdb->posts} AS p WHERE p.post_type IN ('". implode("', '", array( 'product' ) ) ."') AND p.post_status = %s AND NOT EXISTS ( SELECT 1 FROM {$wpdb->ps_product_sku} AS ps WHERE p.ID = ps.post_id ) ORDER BY p.ID ASC LIMIT 0, 500" ,  
  283. 'publish' 
  284. ); 
  285.  
  286. // Or continue sync based latest ID have synced 
  287. } else { 
  288. $all_skus = $wpdb->get_results( 
  289. $wpdb->prepare( 
  290. "SELECT p.ID, p.post_parent FROM {$wpdb->posts} AS p WHERE p.ID > %d AND p.post_type IN ('". implode("', '", array( 'product' ) ) ."') AND p.post_status = %s ORDER BY p.ID ASC LIMIT 0, 500",  
  291. $stopped_ID,  
  292. 'publish' 
  293. ); 
  294.  
  295. if ( $all_skus && is_array( $all_skus ) && count( $all_skus ) > 0 ) { 
  296.  
  297. foreach ( $all_skus as $item ) { 
  298.  
  299. // Stop command after timeout is set 
  300. if ( $end_time > 0 && $end_time <= time() ) { 
  301. break; 
  302.  
  303. $post_id = $item->ID; 
  304. $post_parent = $item->post_parent; 
  305. $sku = get_post_meta( $post_id, '_sku', true ); 
  306.  
  307. if ( empty( $sku ) || '' == trim( $sku ) ) { 
  308. $sku = ''; 
  309.  
  310. $item_existed = $wc_ps_product_sku_data->is_item_existed( $post_id ); 
  311. if ( '0' == $item_existed ) { 
  312. $wc_ps_product_sku_data->insert_item( $post_id, $sku, $post_parent ); 
  313.  
  314. // Migrate Product Out of Stock 
  315. if ( version_compare( WC_VERSION, '3.0.0', '<' ) ) { 
  316. $outofstock = get_post_meta( $post_id, '_stock_status', true ); 
  317. if ( ! empty( $outofstock ) && 'outofstock' == trim( $outofstock ) ) { 
  318. $outofstock = true; 
  319. } else { 
  320. $outofstock = false; 
  321. } else { 
  322. $terms = get_the_terms( $post_id, 'product_visibility' ); 
  323. $term_names = is_array( $terms ) ? wp_list_pluck( $terms, 'name' ) : array(); 
  324. $outofstock = in_array( 'outofstock', $term_names ); 
  325.  
  326. if ( $outofstock ) { 
  327. $wc_ps_postmeta_data->update_item_meta( $post_id, '_stock_status', 'outofstock' ); 
  328. } else { 
  329. $wc_ps_postmeta_data->delete_item_meta( $post_id, '_stock_status' ); 
  330.  
  331. // This function just for auto update to version 3.2.0 
  332. public function migrate_products_out_of_stock() { 
  333. global $wpdb; 
  334. global $wc_ps_postmeta_data; 
  335.  
  336. $all_out_of_stock = $wpdb->get_results( 
  337. $wpdb->prepare( 
  338. "SELECT post_id FROM {$wpdb->postmeta} WHERE meta_key = %s AND meta_value = %s",  
  339. '_stock_status',  
  340. 'outofstock' 
  341. ); 
  342.  
  343. if ( $all_out_of_stock ) { 
  344. foreach ( $all_out_of_stock as $item ) { 
  345. $wc_ps_postmeta_data->update_item_meta( $item->post_id, '_stock_status', 'outofstock' ); 
  346.  
  347. public function synch_full_database() { 
  348. $this->migrate_posts(); 
  349.  
  350. public function delete_post_data( $post_id ) { 
  351. global $wc_ps_posts_data; 
  352. global $wc_ps_postmeta_data; 
  353. global $wc_ps_product_sku_data; 
  354.  
  355. $wc_ps_posts_data->delete_item( $post_id ); 
  356. $wc_ps_postmeta_data->delete_item_metas( $post_id ); 
  357. $wc_ps_product_sku_data->delete_item( $post_id ); 
  358.  
  359. public function synch_save_post( $post_id, $post ) { 
  360. global $wpdb; 
  361. global $wc_ps_posts_data; 
  362. global $wc_ps_postmeta_data; 
  363. global $wc_ps_product_sku_data; 
  364.  
  365. $this->delete_post_data( $post_id ); 
  366.  
  367. $post_types = apply_filters( 'predictive_search_post_types_support', array( 'post', 'page', 'product' ) ); 
  368.  
  369. if ( 'publish' == $post->post_status && in_array( $post->post_type, $post_types ) ) { 
  370.  
  371. $wc_ps_posts_data->update_item( $post_id, $post->post_title, $post->post_type ); 
  372.  
  373. if ( 'product' == $post->post_type ) { 
  374. $sku = get_post_meta( $post_id, '_sku', true ); 
  375. if ( empty( $sku ) || '' == trim( $sku ) ) { 
  376. $sku = ''; 
  377. $wc_ps_product_sku_data->update_item( $post_id, $sku, 0 ); 
  378.  
  379. // Migrate Product Out of Stock 
  380. if ( version_compare( WC_VERSION, '3.0.0', '<' ) ) { 
  381. $outofstock = get_post_meta( $post_id, '_stock_status', true ); 
  382. if ( ! empty( $outofstock ) && 'outofstock' == trim( $outofstock ) ) { 
  383. $outofstock = true; 
  384. } else { 
  385. $outofstock = false; 
  386. } else { 
  387. $terms = get_the_terms( $post_id, 'product_visibility' ); 
  388. $term_names = is_array( $terms ) ? wp_list_pluck( $terms, 'name' ) : array(); 
  389. $outofstock = in_array( 'outofstock', $term_names ); 
  390.  
  391. if ( $outofstock ) { 
  392. $wc_ps_postmeta_data->update_item_meta( $post_id, '_stock_status', 'outofstock' ); 
  393. } else { 
  394. $wc_ps_postmeta_data->delete_item_meta( $post_id, '_stock_status' ); 
  395.  
  396. if ( 'page' == $post->post_type ) { 
  397. global $woocommerce_search_page_id; 
  398.  
  399. // flush rewrite rules if page is editing is WooCommerce Search Result page 
  400. if ( $post_id == $woocommerce_search_page_id ) { 
  401. flush_rewrite_rules(); 
  402.  
  403.  
  404. public function synch_delete_post( $post_id ) { 
  405. global $wc_ps_exclude_data; 
  406.  
  407. $this->delete_post_data( $post_id ); 
  408.  
  409. $post_type = get_post_type( $post_id ); 
  410.  
  411. $wc_ps_exclude_data->delete_item( $post_id, $post_type ); 
  412.  
  413. public function synch_mysql_inserted_post( $post_id = 0 ) { 
  414. if ( $post_id < 1 ) return; 
  415.  
  416. global $wpdb; 
  417. $post_types = apply_filters( 'predictive_search_post_types_support', array( 'post', 'page', 'product' ) ); 
  418.  
  419. $item = $wpdb->get_row( 
  420. $wpdb->prepare( 
  421. "SELECT ID, post_title, post_type, post_parent FROM {$wpdb->posts} WHERE ID = %d AND post_status = %s AND post_type IN ('". implode("', '", $post_types ) ."')" ,  
  422. $post_id,  
  423. 'publish' 
  424. ); 
  425.  
  426. if ( $item ) { 
  427. global $wc_ps_posts_data; 
  428. global $wc_ps_postmeta_data; 
  429. global $wc_ps_product_sku_data; 
  430.  
  431. $item_existed = $wc_ps_posts_data->is_item_existed( $post_id ); 
  432. if ( '0' == $item_existed ) { 
  433. $wc_ps_posts_data->insert_item( $post_id, $item->post_title, $item->post_type ); 
  434.  
  435. if ( in_array( $item->post_type, array( 'product', 'product_variation' ) ) ) { 
  436. $sku = get_post_meta( $post_id, '_sku', true ); 
  437. $post_parent = $item->post_parent; 
  438.  
  439. if ( ( empty( $sku ) || '' == trim( $sku ) ) && $post_parent > 0 ) { 
  440. $sku = get_post_meta( $post_parent, '_sku', true ); 
  441.  
  442. if ( empty( $sku ) || '' == trim( $sku ) ) { 
  443. $sku = ''; 
  444.  
  445. $item_existed = $wc_ps_product_sku_data->is_item_existed( $post_id ); 
  446. if ( '0' == $item_existed ) { 
  447. $wc_ps_product_sku_data->insert_item( $post_id, $sku, $post_parent ); 
  448.  
  449. // Migrate Product Out of Stock 
  450. if ( version_compare( WC_VERSION, '3.0.0', '<' ) ) { 
  451. $outofstock = get_post_meta( $post_id, '_stock_status', true ); 
  452. if ( ! empty( $outofstock ) && 'outofstock' == trim( $outofstock ) ) { 
  453. $outofstock = true; 
  454. } else { 
  455. $outofstock = false; 
  456. } else { 
  457. $terms = get_the_terms( $post_id, 'product_visibility' ); 
  458. $term_names = is_array( $terms ) ? wp_list_pluck( $terms, 'name' ) : array(); 
  459. $outofstock = in_array( 'outofstock', $term_names ); 
  460. if ( $outofstock ) { 
  461. $wc_ps_postmeta_data->update_item_meta( $post_id, '_stock_status', 'outofstock' ); 
  462. } else { 
  463. $wc_ps_postmeta_data->delete_item_meta( $post_id, '_stock_status' );