Advertisement
designbymerovingi

myCRED Woo Adjust Cost based on variation

Jan 20th, 2016
189
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 0.82 KB | None | 0 0
  1. /**
  2.  * Adjust Woo Price in Points
  3.  * If an order item has the product attribute "size"
  4.  * and the size is "large", deduct the extra cost the variation
  5.  * enforces when paying with points.
  6.  * @version 1.0
  7.  */
  8. function mycredpro_adjust_point_cost_woo( $cost, $order, $is_cart, $this ) {
  9.  
  10.     if ( $is_cart ) return $cost;
  11.  
  12.     $items = $order->get_items();
  13.  
  14.     $amount_to_deduct = 0;
  15.     foreach ( $items as $item ) {
  16.  
  17.         if ( ! isset( $item['pa_size'] ) ) continue;
  18.  
  19.         $sizes_that_cost_extra = array( 'L', 'XL', 'XXL' );
  20.  
  21.         if ( in_array( $item['pa_size'], $sizes_that_cost_extra ) )
  22.             $amount_to_deduct = $amount_to_deduct + ( $item['qty'] * 2 );
  23.  
  24.     }
  25.  
  26.     if ( $amount_to_deduct > 0 )
  27.         $cost = $cost - $amount_to_deduct;
  28.  
  29.     return $cost;
  30.  
  31. }
  32. add_filter( 'mycred_woo_order_cost', 'mycredpro_adjust_point_cost_woo', 10, 4 );
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement