kilbot
5/30/2017 - 5:51 AM

Using a wholesale price for all POS products

Using a wholesale price for all POS products

<?php 

// this goes in your theme functions.php file

function my_custom_product_response($response, $product) {
  
  // only change the response for POS requests
  if( ! is_pos() ) {
    return $response;
  }
  
  // get the old data
  $data = $response->get_data();
  
  // change the price to the wholesale price
  if( $wholesale_price = get_post_meta( $product->get_id(), 'wholesale_price', true  ) ) {
    $data['price'] = $wholesale_price;
  }
  
  // reset the new response data
  $response->set_data($data);
  return $response;
}

// filter the WC REST API response
add_filter( 'woocommerce_rest_prepare_product_object', 'my_custom_product_response', 10, 2 );
add_filter( 'woocommerce_rest_prepare_product_variation_object', 'my_custom_product_response', 10, 2 );