WordPress.org

Support

Support » Plugins and Hacks » WooCommerce » How to return array in function for hook

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/

Viewing 1 replies (of 1 total)
  • If you would just stick to the original topic (which I‘ve replied to providing an example), 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.
Skip to toolbar