User Tools

Site Tools


start:website:source

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revision Previous revision
Next revision
Previous revision
start:website:source [2016/10/12 09:07]
andre [Add ship to store option for dealers with less-than-minimum fee]
start:website:source [2016/10/12 10:52] (current)
andre [Add ship to store option for dealers with less-than-minimum fee]
Line 22: Line 22:
 <​code>​ <​code>​
 /** /**
- * @snippet ​  ​Add ​field to checkout+ * @snippet ​  ​Add ​Ship to Store field at checkout ​if user is logged in as a dealer
  * @author ​   André Le Comte  * @author ​   André Le Comte
  **/  **/
Line 29: Line 29:
 function custom_checkout_field( $checkout ) { function custom_checkout_field( $checkout ) {
    
- //​Check if user is a dealer + //​Check if user is signed in as a dealer ​i.e., user's role is '​customer'​ 
- ​$user_is_dealer = is_user_a_dealer( ​117 );+ ​$user_is_dealer = is_user_a_dealer( ​customer ​);
    
  //​User is dealer so show additional fields  //​User is dealer so show additional fields
Line 49: Line 49:
 /** /**
  * @snippet Check if user is logged in as a dealer  * @snippet Check if user is logged in as a dealer
- * @param $product_id 
- * @return bool 
  * @author André Le Comte  * @author André Le Comte
  */  */
-function is_user_a_dealer( $product_id ​) { +function is_user_a_dealer( $user_roles ​) { 
- //​Check to see if user has product ​in cart+ //​Check to see if user is logged ​in as a dealer
  ​global $woocommerce;​  ​global $woocommerce;​
    
- //​flag ​no book in cart + //​flag ​not dealer 
- $book_in_cart ​= false;+ $user_is_dealer ​= false;
    
- ​foreach ​$woocommerce->​cart->​get_cart() as $cart_item_key => $values ​{ +$user_data = get_userdataget_current_user_id() ); 
- $_product ​= $values['​data'​]; +$user_roles ​= $user_data->​roles
-  +if( in_array('​customer', ​$user_roles) ​) { 
- if ( $_product->​id === $product_id ​) { + //user is logged ​in as a dealer
- //book is in cart+ $user_is_dealer ​= true;
- $book_in_cart ​= true;+
    
  }  }
  }  }
    
- ​return $book_in_cart;+ ​return $user_is_dealer;
    
 } }
 </​code>​ </​code>​
start/website/source.1476288439.txt.gz · Last modified: 2016/10/12 09:07 by andre