Title: How to return array in function for hook
Last modified: August 20, 2016

---

# How to return array in function for hook

 *  [ardziej](https://wordpress.org/support/users/ardziej/)
 * (@ardziej)
 * [13 years, 1 month ago](https://wordpress.org/support/topic/how-to-return-array-in-function-for-hook/)
 * I know how add filter, but I can’t return array for woocommerce_available_variation.
   
   This is code from some woocommerce file
 *     ```
       $available_variations[] = apply_filters( 'woocommerce_available_variation', array(
       					'variation_id' 			=> $child_id,
       					'attributes' 			=> $variation_attributes,
       					'image_src' 			=> $image,
       					'image_link' 			=> $image_link,
       					'image_title'			=> $image_title,
       					'price_html' 			=> $this->min_variation_price != $this->max_variation_price ? '<span class="price">' . $variation->get_price_html() . '</span>' : '',
       					'availability_html' 	=> $availability_html,
       					'sku' 					=> $variation->get_sku(),
       					'weight'				=> $variation->get_weight() . ' ' . esc_attr( get_option('woocommerce_weight_unit' ) ),
       					'dimensions'			=> $variation->get_dimensions(),
       					'min_qty' 				=> 1,
       					'max_qty' 				=> $this->backorders_allowed() ? '' : $variation->stock,
       					'backorders_allowed' 	=> $this->backorders_allowed(),
       					'is_in_stock'			=> $variation->is_in_stock(),
       					'is_downloadable' 		=> $variation->is_downloadable() ,
       					'is_virtual' 			=> $variation->is_virtual(),
       					'is_sold_individually' 	=> $variation->is_sold_individually() ? 'yes' : 'no',
       				), $this, $variation );
       ```
   
 * Just
 *     ```
       return  array(
       					'variation_id' 			=> $child_id,
       					'attributes' 			=> $variation_attributes,
       					'image_src' 			=> $image,
       					'image_link' 			=> $image_link,
       					'image_title'			=> $image_title,
       					'price_html' 			=> $this->min_variation_price != $this->max_variation_price ? '<span class="price">' . $variation->get_price_html() . '</span>' : '',
       					'availability_html' 	=> $availability_html,
       					'sku' 					=> $variation->get_sku(),
       					'weight'				=> $variation->get_weight() . ' ' . esc_attr( get_option('woocommerce_weight_unit' ) ),
       					'dimensions'			=> $variation->get_dimensions(),
       					'min_qty' 				=> 1,
       					'max_qty' 				=> $this->backorders_allowed() ? '' : $variation->stock,
       					'backorders_allowed' 	=> $this->backorders_allowed(),
       					'is_in_stock'			=> $variation->is_in_stock(),
       					'is_downloadable' 		=> $variation->is_downloadable() ,
       					'is_virtual' 			=> $variation->is_virtual(),
       					'is_sold_individually' 	=> $variation->is_sold_individually() ? 'yes' : 'no',
       				);
       ```
   
 * How i can pass $this-> ?
 * [http://wordpress.org/extend/plugins/woocommerce/](http://wordpress.org/extend/plugins/woocommerce/)

Viewing 1 replies (of 1 total)

 *  [Coen Jacobs](https://wordpress.org/support/users/coenjacobs/)
 * (@coenjacobs)
 * [13 years, 1 month ago](https://wordpress.org/support/topic/how-to-return-array-in-function-for-hook/#post-3619393)
 * If you would just stick to the original topic (which I[‘ve replied to providing an example](http://wordpress.org/support/topic/woocommerce_available_variation-how-to-do-own-filter?replies=4#post-4049355)),
   it would make the support here a lot easier and keep the overview in your topics.
 * You’re talking about ‘pass’ `$this->` but that makes no sense out of context.
   What ís `$this->` for you? Are you using it within an object, or else it makes
   no sense?
 * If you want to return the contents of the original array via a filter, then you
   can also just remove your hooks for using that filter. If you want to change 
   a little bit, you can change just that and then return the array again. This 
   is all pretty much explained in my previous example.
 * If you’re still not sure how to do this, please explain what exactly you are 
   trying to do (in this topic please, don’t make me chase you) and be more detailed
   in explaining it than you’ve been so far.

Viewing 1 replies (of 1 total)

The topic ‘How to return array in function for hook’ is closed to new replies.

 * ![](https://ps.w.org/woocommerce/assets/icon.svg?rev=3234504)
 * [WooCommerce](https://wordpress.org/plugins/woocommerce/)
 * [Frequently Asked Questions](https://wordpress.org/plugins/woocommerce/#faq)
 * [Support Threads](https://wordpress.org/support/plugin/woocommerce/)
 * [Active Topics](https://wordpress.org/support/plugin/woocommerce/active/)
 * [Unresolved Topics](https://wordpress.org/support/plugin/woocommerce/unresolved/)
 * [Reviews](https://wordpress.org/support/plugin/woocommerce/reviews/)

 * 1 reply
 * 2 participants
 * Last reply from: [Coen Jacobs](https://wordpress.org/support/users/coenjacobs/)
 * Last activity: [13 years, 1 month ago](https://wordpress.org/support/topic/how-to-return-array-in-function-for-hook/#post-3619393)
 * Status: not resolved