php - Woocommerce add_filter only works when logged in -


i use filter provided woocommerce composite products plugin update quantities of products in set. when logged in filter works intended, when not logged in quantities not updated.

i use 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) {    $category = $_post['soort'];    $retrieve_data = wc()->session->get( 'quantities' );    $postname = $product->post->post_name;      if($postname == 'product-basis') {         return 1;     }     else if (strpos($postname, 'product-')) {         return 1;     } else {         $value = is_numeric($retrieve_data[$category][$postname]) && $retrieve_data[$category][$postname] > 0 ? $retrieve_data[$category][$postname] : 1;         return (int)$value;     } } 

the values of $soort_verwarming , $retrieve_data available, led me thinking filter somehow not working when user not logged in.

$retrieve_data[$category][$postname] corresponds number should returned each product , update quantity.

are there reasons why add_filter not work not logged in users?

adding header fixed problem me:

wc()->session->set_customer_session_cookie(true); 

i used wordpress session somewhere else save data needed update quantities with. guess session not being set customers logged out, explains why working when logged in.

any additional info if needed: https://docs.woothemes.com/wc-apidocs/source-class-wc_session_handler.html#73-91


Comments

Popular posts from this blog

ios - RestKit 0.20 — CoreData: error: Failed to call designated initializer on NSManagedObject class (again) -

java - Digest auth with Spring Security using javaconfig -

laravel - PDOException in Connector.php line 55: SQLSTATE[HY000] [1045] Access denied for user 'root'@'localhost' (using password: YES) -