samedi 28 mai 2016

Woocommerce add_filter only works when logged in

I use a filter provided by Woocommerce Composite Products plugin to update quantities of products in a set. When I am logged in this filter works as intended, but when I am not logged in the quantities are not updated.

I use the following code:

add_filter( 'woocommerce_composited_product_quantity', 'update_quantity', 10, 6);

function update_quantity($qty_value, $min_quantity, $max_quantity, $product, $component_id, $composite_product)
{

  $soort_verwarming = $_POST['soort'];

  $retrieve_data = WC()->session->get( 'quantities' );

  $postname = $product->post->post_name;

    if($postname == 'verdeler-basis') {
        return 1;
    }
    else if (strpos($postname, 'verdeler-')) {
        return 1;
    } else {
        $value = is_numeric($retrieve_data[$soort_verwarming][$postname]) && $retrieve_data[$soort_verwarming][$postname] > 0 ? $retrieve_data[$soort_verwarming][$postname] : 1;
        return (int)$value;
    }
}

The values of $soort_verwarming and $retrieve_data are available, which led me thinking that the filter is somehow not working when a user is not logged in.

$retrieve_data[$soort_verwarming][$postname] corresponds to a number which should be returned for each product and update its quantity.

Are there reasons why add_filter would not work for not logged in users?



via Chebli Mohamed

Aucun commentaire:

Enregistrer un commentaire