Title: shanerutter's Replies | WordPress.org

---

# shanerutter

  [  ](https://wordpress.org/support/users/shanerutter/)

 *   [Profile](https://wordpress.org/support/users/shanerutter/)
 *   [Topics Started](https://wordpress.org/support/users/shanerutter/topics/)
 *   [Replies Created](https://wordpress.org/support/users/shanerutter/replies/)
 *   [Reviews Written](https://wordpress.org/support/users/shanerutter/reviews/)
 *   [Topics Replied To](https://wordpress.org/support/users/shanerutter/replied-to/)
 *   [Engagements](https://wordpress.org/support/users/shanerutter/engagements/)
 *   [Favorites](https://wordpress.org/support/users/shanerutter/favorites/)

 Search replies:

## Forum Replies Created

Viewing 3 replies - 1 through 3 (of 3 total)

 *   Forum: [Plugins](https://wordpress.org/support/forum/plugins-and-hacks/)
    In
   reply to: [[Social Feed Gallery] Keeps disconnecting and shows a horrible red warning instead](https://wordpress.org/support/topic/keeps-disconnecting-and-shows-a-horrible-red-warning-instead/)
 *  [shanerutter](https://wordpress.org/support/users/shanerutter/)
 * (@shanerutter)
 * [5 years, 7 months ago](https://wordpress.org/support/topic/keeps-disconnecting-and-shows-a-horrible-red-warning-instead/#post-13745032)
 * There is no need for the warning to be public, it should only display if you 
   are logged in as an admin. The public does not need to see a big red message 
   telling them somthing has gone wrong.
 *   Forum: [Plugins](https://wordpress.org/support/forum/plugins-and-hacks/)
    In
   reply to: [[Social Feed Gallery] Keeps disconnecting and shows a horrible red warning instead](https://wordpress.org/support/topic/keeps-disconnecting-and-shows-a-horrible-red-warning-instead/)
 *  [shanerutter](https://wordpress.org/support/users/shanerutter/)
 * (@shanerutter)
 * [5 years, 8 months ago](https://wordpress.org/support/topic/keeps-disconnecting-and-shows-a-horrible-red-warning-instead/#post-13706993)
 * Simular issue, the token keeps expring and just shows a red message on the website
   to all users.
 * [https://snipboard.io/bKx2rq.jpg](https://snipboard.io/bKx2rq.jpg)
 * Does the token not auto renew? Below is the text as its not easily readable.
 * Error validating access token: Session has expired on Sunday, 22-Nov-20 10:54:
   25 PST. The current time is Wednesday, 25-Nov-20 02:48:55 PST.
    -  This reply was modified 5 years, 8 months ago by [shanerutter](https://wordpress.org/support/users/shanerutter/).
    -  This reply was modified 5 years, 8 months ago by [shanerutter](https://wordpress.org/support/users/shanerutter/).
 *   Forum: [Plugins](https://wordpress.org/support/forum/plugins-and-hacks/)
    In
   reply to: [[Stock Locations for WooCommerce] Rest api](https://wordpress.org/support/topic/rest-api-84/)
 *  [shanerutter](https://wordpress.org/support/users/shanerutter/)
 * (@shanerutter)
 * [6 years, 2 months ago](https://wordpress.org/support/topic/rest-api-84/#post-12884018)
 * Hi, I needed the ability to use the REST api also, as you say you can use the
   meta_data way to set the actual location stock level. But I also need the abilty
   to enable / disable the stock locations as well. So I quickly made this.
 * Will show “stock_location” when get products/*
    Allow update stock_locations 
   when you PUT products/*
 * Its a temp solutuon until Alex get somthing into the actual plugin 🙂
 *     ```
       /*
        * Include stock_location
        */
       function custom_woocommerce_rest_prepare_product($response, $post) {
       	$post_id = is_callable(array($post, 'get_id')) ? $post->get_id() : (!empty($post->ID) ? $post->ID : null);
   
       	if (empty($response->data['stock_locations'])) {
       		$terms = array();
   
       		foreach (wp_get_post_terms($post_id, 'location') as $term) {
       			$terms[] = array(
       				'id'   => $term->term_id,
       				'name' => $term->name,
       				'slug' => $term->slug,
       			);
       		}
   
       		$response->data['stock_locations'] = $terms;
       	}
   
       	return $response;
       }
       add_filter('woocommerce_rest_prepare_product', 'custom_woocommerce_rest_prepare_product', 10, 2); // WC 2.6.x
       add_filter('woocommerce_rest_prepare_product_object', 'custom_woocommerce_rest_prepare_product', 10, 2); // WC 3.x
   
       /*
        * Update stock_location
        */
       function custom_woocommerce_rest_insert_product($post, $request) {
       	if (isset($request['stock_locations']) && is_array($request['stock_locations']) && sizeof($request['stock_locations'])) {
       		$terms = array_map('absint', $request['stock_locations']);
       		wp_set_object_terms($post->id, $terms, 'location');
       	}
       }
       add_action('woocommerce_rest_insert_product', 'custom_woocommerce_rest_insert_product', 10, 3); // WC 2.6.x
       add_action('woocommerce_rest_insert_product_object', 'custom_woocommerce_rest_insert_product', 10, 3); // WC 3.x
       ```
   

Viewing 3 replies - 1 through 3 (of 3 total)