Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /**
- * Adjust Woo Price in Points
- * If an order item has the product attribute "size"
- * and the size is "large", deduct the extra cost the variation
- * enforces when paying with points.
- * @version 1.0
- */
- function mycredpro_adjust_point_cost_woo( $cost, $order, $is_cart, $this ) {
- if ( $is_cart ) return $cost;
- $items = $order->get_items();
- $amount_to_deduct = 0;
- foreach ( $items as $item ) {
- if ( ! isset( $item['pa_size'] ) ) continue;
- $sizes_that_cost_extra = array( 'L', 'XL', 'XXL' );
- if ( in_array( $item['pa_size'], $sizes_that_cost_extra ) )
- $amount_to_deduct = $amount_to_deduct + ( $item['qty'] * 2 );
- }
- if ( $amount_to_deduct > 0 )
- $cost = $cost - $amount_to_deduct;
- return $cost;
- }
- add_filter( 'mycred_woo_order_cost', 'mycredpro_adjust_point_cost_woo', 10, 4 );
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement