Created
July 10, 2023 05:17
-
-
Save sachyya/ba5293c478f2bbb89691e9bd45d7a452 to your computer and use it in GitHub Desktop.
Add stock status to product schema
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_filter( 'cm_tsfwc_product_fields', 'your_slug_add_stock_status_to_schema' ); | |
function your_slug_add_stock_status_to_schema( $product_fields ) { | |
$product_fields[] = [ 'name' => 'stock_status', 'type' => 'string' ]; | |
return $product_fields; | |
} | |
add_filter( 'cm_tsfwc_data_before_entry', 'your_slug_add_data_before_entry', 10, 4 ); | |
function your_slug_add_data_before_entry( $formatted_data, $raw_data, $object_id, $schema_name ) { | |
if( $schema_name === 'product' ) { // only add data if the schema is product | |
$stock_status = $raw_data->get_stock_status(); | |
$formatted_data['stock_status'] = $stock_status; | |
} | |
return $formatted_data; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment