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.1
- */
- function mycredpro_adjust_point_cost_woo( $cost, $order, $is_cart, $this ) {
- if ( $is_cart ) return $cost;
- $items = $order->get_items();
- $amount_to_deduct = 0;
- $product_factory = new WC_Product_Factory();
- foreach ( $items as $item_id => $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 ) ) {
- $product = $product_factory->get_product( $item['product_id'] );
- $amount_to_deduct = $amount_to_deduct + ( $item['qty'] * 2 );
- $order->update_product( $item_id, $product, array(
- 'qty' => $item['qty'],
- 'totals' => array(
- 'subtotal' => ( $product->get_price() - 2 )
- )
- ) );
- }
- }
- if ( $amount_to_deduct > 0 ) {
- $order->calculate_totals();
- $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