PHP 8.2.31
Preview: ProductItemTrait.php Size: 3.54 KB
/home/nshryvcy/radiantskinclinics.org/wp-content/plugins/woocommerce/src/StoreApi/Utilities/ProductItemTrait.php

<?php
namespace Automattic\WooCommerce\StoreApi\Utilities;

/**
 * ProductItemTrait
 *
 * Shared functionality for formating product item data.
 */
trait ProductItemTrait {
	/**
	 * Get an array of pricing data.
	 *
	 * @param \WC_Product $product Product instance.
	 * @param string      $tax_display_mode If returned prices are incl or excl of tax.
	 * @return array
	 */
	protected function prepare_product_price_response( \WC_Product $product, $tax_display_mode = '' ) {
		$tax_display_mode = $this->get_tax_display_mode( $tax_display_mode );
		$price_function   = $this->get_price_function_from_tax_display_mode( $tax_display_mode );
		$prices           = parent::prepare_product_price_response( $product, $tax_display_mode );

		// Add raw prices (prices with greater precision).
		$prices['raw_prices'] = array(
			'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, array( 'price' => $product->get_regular_price() ) ), wc_get_rounding_precision() ),
			'sale_price'    => $this->prepare_money_response( $price_function( $product, array( 'price' => $product->get_sale_price() ) ), wc_get_rounding_precision() ),
		);

		return $prices;
	}

	/**
	 * 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 = array();

		if ( ! is_iterable( $variation_data ) ) {
			return $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 ) {

					/**
					 * Filters the variation option name for taxonomy attributes.
					 *
					 * @since 10.7.0
					 *
					 * @internal Matches filter name in WooCommerce core.
					 *
					 * @param string      $name     The term name to display.
					 * @param \WP_Term    $term     Term object.
					 * @param string      $taxonomy Taxonomy name.
					 * @param \WC_Product $product  Product data.
					 * @return string
					 */
					$value = apply_filters( 'woocommerce_variation_option_name', $term->name, $term, $taxonomy, $product );
				}
				$label = wc_attribute_label( $taxonomy );
			} else {

				/**
				 * Filters the variation option name.
				 *
				 * Filters the variation option name for custom option slugs.
				 *
				 * @since 2.5.0
				 *
				 * @internal Matches filter name in WooCommerce core.
				 *
				 * @param string $value The name to display.
				 * @param null $unused Unused because this is not a variation taxonomy.
				 * @param string $taxonomy Taxonomy or product attribute name.
				 * @param \WC_Product $product Product data.
				 * @return string
				 */
				$value = apply_filters( 'woocommerce_variation_option_name', $value, null, $taxonomy, $product );
				$label = wc_attribute_label( str_replace( 'attribute_', '', $key ), $product );
			}

			$return[] = array(
				'raw_attribute' => $this->prepare_html_response( $key ),
				'attribute'     => $this->prepare_html_response( $label ),
				'value'         => $this->prepare_html_response( $value ),
			);
		}

		return $return;
	}
}

Directory Contents

Dirs: 0 × Files: 21

Name Size Perms Modified Actions
14.76 KB lrw-r--r-- 2026-02-23 17:58:34
Edit Download
1.49 KB lrw-r--r-- 2024-04-30 19:35:34
Edit Download
48.42 KB lrw-r--r-- 2026-03-12 20:10:34
Edit Download
1.81 KB lrw-r--r-- 2025-06-23 19:46:28
Edit Download
10.82 KB lrw-r--r-- 2025-06-23 19:46:28
Edit Download
1.76 KB lrw-r--r-- 2024-09-04 20:34:26
Edit Download
5.45 KB lrw-r--r-- 2025-07-29 12:34:58
Edit Download
5.67 KB lrw-r--r-- 2026-01-19 14:46:18
Edit Download
2.02 KB lrw-r--r-- 2025-03-03 22:28:12
Edit Download
3.29 KB lrw-r--r-- 2025-12-22 17:20:32
Edit Download
32.10 KB lrw-r--r-- 2026-05-05 14:26:50
Edit Download
2.05 KB lrw-r--r-- 2023-12-27 00:45:02
Edit Download
3.65 KB lrw-r--r-- 2025-05-12 21:07:28
Edit Download
3.54 KB lrw-r--r-- 2026-03-30 17:12:24
Edit Download
1.82 KB lrw-r--r-- 2026-03-30 17:12:24
Edit Download
21.61 KB lrw-r--r-- 2026-05-05 14:26:50
Edit Download
9.25 KB lrw-r--r-- 2025-07-29 12:34:58
Edit Download
10.11 KB lrw-r--r-- 2025-07-29 12:34:58
Edit Download
6.14 KB lrw-r--r-- 2025-03-03 22:28:12
Edit Download
794 B lrw-r--r-- 2024-02-27 18:59:46
Edit Download
1.73 KB lrw-r--r-- 2023-12-27 00:45:02
Edit Download

If ZipArchive is unavailable, a .tar will be created (no compression).