Ready to get started?Download WordPress


WooCommerce - excelling eCommerce
[resolved] woocommerce_available_variation - how to do own filter? (4 posts)

  1. ardziej
    Posted 1 year ago #

    How I can replace woocommerce_available_variation ?
    I've got erros. Which vars I've to give to function?


  2. Coen Jacobs
    Plugin Author

    Posted 1 year ago #

    Like I mentioned in my reply to your other topic, you are probably best of reading the Plugin API documentation to get you started. If you get errors or anything like that, please post them here so we can look. You also should post the code how you are hooking into this specific filter.

  3. ardziej
    Posted 1 year ago #

    Hi, i know how add filter.

    $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 );

    But I don't know how I can return array in my function with these vars.

  4. Coen Jacobs
    Plugin Author

    Posted 1 year ago #

    Please take my advice and read the documentation I linked to. This is not how you should use a filter. Quick example of how it should be done:

    add_filter( 'woocommerce_available_variation', 'cj_ woocommerce_available_variation' );
    function cj_ woocommerce_available_variation( $variations ) {
    array_push( $variations, array( 'test_key' => 'test value' );
    return $variations;

    This adds the array( 'test_key' => 'test value' ) to the array (via the filter woocommerce_available_variation) and then returns it.

Topic Closed

This topic has been closed to new replies.

About this Plugin

About this Topic


No tags yet.