Created
March 19, 2018 15:35
-
-
Save kilbot/113084c231ab1b2a65f3431b15a2f487 to your computer and use it in GitHub Desktop.
Change the product price based on store id
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
// this goes in your theme functions.php file | |
function my_custom_product_response( $response, $product ) { | |
// early exit if user is not in the POS | |
if( ! is_pos() ) { | |
return $response; | |
} | |
// get the old product data | |
$data = $response->get_data(); | |
// get the current logged in store id | |
$store_id = get_user_option( 'woocommerce_pos_store' ); | |
// change the price based on store id | |
if( $store_id == 1234 ) { | |
$data['price'] = '2.99'; | |
} | |
// 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 ); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment