Last active
April 3, 2025 15:44
-
-
Save kilbot/8249ea198fefcb3e0e07b7afce362eab to your computer and use it in GitHub Desktop.
Example custom product response for POS Stores
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 | |
/** | |
* add to your theme functions.php file | |
*/ | |
function my_custom_product_response( $response, $product, $request ) { | |
// only intercept requests from the POS | |
if( ! function_exists('woocommerce_pos_request') || ! woocommerce_pos_request() ) | |
return $response; | |
$store_id = $request->get_param( 'store_id' ); | |
$product_id = $product->get_id(); | |
$data = $response->get_data(); | |
/** | |
* This is the important part: using the POS Store ID and the Product ID you | |
* can look up the stock quantity value. This will depend on your inventory plugin. | |
*/ | |
$data['stock_quantity'] = ''; | |
// Save the updated response | |
$response->set_data( $data ); | |
return $response; | |
} | |
// get the product respense priority 20 (after default POS code) | |
add_filter( 'woocommerce_rest_prepare_product_object', 'my_custom_product_response', 20, 1 ); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment