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/11 11:39]
andre
start:website:source [2016/10/12 10:52] (current)
andre [Add ship to store option for dealers with less-than-minimum fee]
Line 18: Line 18:
    
 add_action( '​woocommerce_cart_calculate_fees',​ '​add_CA_cart_tax'​ );</​code>​ add_action( '​woocommerce_cart_calculate_fees',​ '​add_CA_cart_tax'​ );</​code>​
 +
 +====== Add ship to store option for dealers with less-than-minimum fee ======
 +<​code>​
 +/**
 + * @snippet ​  Add Ship to Store field at checkout if user is logged in as a dealer
 + * @author ​   André Le Comte
 + **/
 +add_action( '​woocommerce_after_order_notes',​ '​custom_checkout_field'​ );
 + 
 +function custom_checkout_field( $checkout ) {
 + 
 + //​Check if user is signed in as a dealer i.e., user's role is '​customer'​
 + ​$user_is_dealer = is_user_a_dealer( customer );
 + 
 + //​User is dealer so show additional fields
 + if ( $user_is_dealer === true ) {
 + echo '<​div id="​my_custom_checkout_field"><​h3>'​ . __( 'Ship to store' ) . '</​h3><​p style="​margin:​ 0 0 8px;">​Ship to store</​p>';​
 + 
 + ​woocommerce_form_field( '​ship_to_store_checkbox',​ array(
 + '​type' ​ => '​checkbox',​
 + '​class'​ => array( '​ship-to-store-checkbox form-row-wide'​ ),
 + '​label'​ => __( '​Yes'​ ),
 + ), $checkout->​get_value( '​ship_to_store_checkbox'​ ) );
 + 
 + echo '</​div>';​
 + }
 + 
 +}
 + 
 +/**
 + * @snippet Check if user is logged in as a dealer
 + * @author André Le Comte
 + */
 +function is_user_a_dealer( $user_roles ) {
 + //​Check to see if user is logged in as a dealer
 + ​global $woocommerce;​
 + 
 + //​flag not dealer
 + ​$user_is_dealer = false;
 + 
 +$user_data = get_userdata( get_current_user_id() );
 +$user_roles = $user_data->​roles;​
 +if( in_array('​customer',​ $user_roles) ) {
 + //​user is logged in as a dealer!
 + ​$user_is_dealer = true;
 + 
 + }
 + }
 + 
 + ​return $user_is_dealer;​
 + 
 +}
 +</​code>​
start/website/source.1476211192.txt.gz · Last modified: 2016/10/11 11:39 by andre