WordPress.org

Ready to get started?Download WordPress

Forums

WooCommerce - excelling eCommerce
How to return array in function for hook (2 posts)

  1. ardziej
    Member
    Posted 1 year ago #

    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/

  2. Coen Jacobs
    Member
    Plugin Author

    Posted 1 year ago #

    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.

Topic Closed

This topic has been closed to new replies.

About this Plugin

About this Topic

Tags

No tags yet.