t_price_response( $product, $tax_display_mode ); // Add raw prices (prices with greater precision). $prices['raw_prices'] = [ 'precision' => wc_get_rounding_precision(), 'price' => $this->prepare_money_response( $price_function( $product ), wc_get_rounding_precision() ), 'regular_price' => $this->prepare_money_response( $price_function( $product, [ 'price' => $product->get_regular_price() ] ), wc_get_rounding_precision() ), 'sale_price' => $this->prepare_money_response( $price_function( $product, [ 'price' => $product->get_sale_price() ] ), wc_get_rounding_precision() ), ]; return $prices; } /** * Returns the remaining stock for a product if it has stock. * * This also factors in draft orders. * * @param \WC_Product $product Product instance. * @return integer|null */ protected function get_remaining_stock( \WC_Product $product ) { if ( is_null( $product->get_stock_quantity() ) ) { return null; } $draft_order = wc()->session->get( 'store_api_draft_order', 0 ); $reserve_stock = new ReserveStock(); $reserved_stock = $reserve_stock->get_reserved_stock( $product, $draft_order ); return $product->get_stock_quantity() - $reserved_stock; } /** * Format variation data, for example convert slugs such as attribute_pa_size to Size. * * @param array $variation_data Array of data from the cart. * @param \WC_Product $product Product data. * @return array */ protected function format_variation_data( $variation_data, $product ) { $return = []; foreach ( $variation_data as $key => $value ) { $taxonomy = wc_attribute_taxonomy_name( str_replace( 'attribute_pa_', '', urldecode( $key ) ) ); if ( taxonomy_exists( $taxonomy ) ) { // If this is a term slug, get the term's nice name. $term = get_term_by( 'slug', $value, $taxonomy ); if ( ! is_wp_error( $term ) && $term && $term->name ) { $value = $term->name; } $label = wc_attribute_label( $taxonomy ); } else { // If this is a custom option slug, get the options name. $value = apply_filters( 'woocommerce_variation_option_name', $value, null, $taxonomy, $product ); $label = wc_attribute_label( str_replace( 'attribute_', '', $key ), $product ); } $return[] = [ 'attribute' => $this->prepare_html_response( $label ), 'value' => $this->prepare_html_response( $value ), ]; } return $return; } }