WC_Product_Data_Store_CPT::get_data_for_lookup_table()
Get data to save to a lookup table.
Method of the class: WC_Product_Data_Store_CPT{}
No Hooks.
Return
Array
.
Usage
// protected - for code of main (parent) or child class $result = $this->get_data_for_lookup_table( $id, $table );
- $id(int) (required)
- ID of object to update.
- $table(string) (required)
- Lookup table name.
Changelog
Since 3.6.0 | Introduced. |
WC_Product_Data_Store_CPT::get_data_for_lookup_table() WC Product Data Store CPT::get data for lookup table code WC 9.4.2
protected function get_data_for_lookup_table( $id, $table ) { if ( 'wc_product_meta_lookup' === $table ) { $price_meta = (array) get_post_meta( $id, '_price', false ); $manage_stock = get_post_meta( $id, '_manage_stock', true ); $stock = 'yes' === $manage_stock ? wc_stock_amount( get_post_meta( $id, '_stock', true ) ) : null; $price = wc_format_decimal( get_post_meta( $id, '_price', true ) ); $sale_price = wc_format_decimal( get_post_meta( $id, '_sale_price', true ) ); $product_data = array( 'product_id' => absint( $id ), 'sku' => get_post_meta( $id, '_sku', true ), 'virtual' => 'yes' === get_post_meta( $id, '_virtual', true ) ? 1 : 0, 'downloadable' => 'yes' === get_post_meta( $id, '_downloadable', true ) ? 1 : 0, 'min_price' => reset( $price_meta ), 'max_price' => end( $price_meta ), 'onsale' => $sale_price && $price === $sale_price ? 1 : 0, 'stock_quantity' => $stock, 'stock_status' => get_post_meta( $id, '_stock_status', true ), 'rating_count' => array_sum( array_map( 'intval', (array) get_post_meta( $id, '_wc_rating_count', true ) ) ), 'average_rating' => get_post_meta( $id, '_wc_average_rating', true ), 'total_sales' => get_post_meta( $id, 'total_sales', true ), 'tax_status' => get_post_meta( $id, '_tax_status', true ), 'tax_class' => get_post_meta( $id, '_tax_class', true ), ); if ( get_option( 'woocommerce_schema_version', 0 ) >= 920 ) { $product_data['global_unique_id'] = get_post_meta( $id, '_global_unique_id', true ); } return $product_data; } return array(); }