php - add to cart button work with price of zero -


i have variable products in woocommerce have 3 skus. each sku has2 options (size , color) , has retail , wholesale pricing set each variation. i'm using plugin set wholesale pricing. link wholesale plugin

based on size, in ounces, of skus have price set 0 retail customers. sample product set skus follows:

500ml - wholesale = $9.95 retail =$19.95  250ml - wholesale $4.75 retail =$9.95  1000ml wholesale = $39.95 retail = $0.00 

some skus set 0 (0) retail pricing because 1000ml size not available retail shoppers. when retail customer chooses option of 1000ml message "sorry, product unavailable. please choose different combination." perfect. if wholesale user logged in , chooses 1000ml want show price , allow them place in cart. instead shows item price , cart button disabled. and, message shows "sorry, product unavailable. please choose different combination." see link screenshot example

i found hook show if product purchasable or not, don't know how alter allow purchases. since have several products set in way, doesn't seem make sense me enter product 2 times , hide wholesale product general population. possible want do, or creating 2 products way go?

/** * returns false if product cannot bought. * * @return bool */         public function is_purchasable() {                 return apply_filters( 'woocommerce_is_purchasable', $this->exists() && ( 'publish' === $this->get_status() || current_user_can( 'edit_post', $this->get_id() ) ) && '' !== $this->get_price(), $this );         } 

i found snippet gets user role

function get_user_role() {     global $current_user;      $user_roles = $current_user->roles;     $user_role = array_shift($user_roles);      return $user_role; } 

so if return user role wholesale_customer work?

function user_filter_addtocart_for_shop_page(){ $user_role = get_user_role(); $role_id = get_role('wholesale_customer'); if($user_role == $role_id){     remove_action( 'woocommerce_after_shop_loop_item', 'woocommerce_template_loop_add_to_cart', 10 ); } 


Comments

Popular posts from this blog

php - Permission denied. Laravel linux server -

google bigquery - Delta between query execution time and Java query call to finish -

python - Pandas two dataframes multiplication? -