WC_Shipping::get_package_hash │ private │ WC 1.0

Generate the shipping-rate cache hash for a package.

Метод класса: WC_Shipping{}

Возвращает

string.

Использование

// private - только в коде основоного (родительского) класса
$result = $this->get_package_hash( $package_to_hash ): string;
$package_to_hash(массив) (обязательный)
Package of cart items.

Код WC_Shipping::get_package_hash() WC 11.3.0

private function get_package_hash( array $package_to_hash ): string {
	// The rate taxes depend on the tax address, so a new tax address must not reuse saved rates.
	if ( wc_tax_enabled() && WC()->customer instanceof WC_Customer ) {
		$package_to_hash['tax_location'] = WC()->customer->get_taxable_address();
	}

	/**
	 * Filters package fields that should not affect the shipping-rate cache hash.
	 *
	 * @since 11.0.0
	 *
	 * @param array $ignored_fields Package field names ignored while generating the cache hash.
	 * @param array $package        Package of cart items.
	 */
	$ignored_fields = apply_filters(
		'woocommerce_shipping_package_hash_ignored_fields',
		array(
			'subtotal',
			'total',
			'package_id',
			'package_name',
			'rates',
			'package_index',
		),
		$package_to_hash
	);

	foreach ( array_unique( array_filter( (array) $ignored_fields, 'is_string' ) ) as $field ) {
		unset( $package_to_hash[ $field ] );
	}

	// Remove data objects so hashes are consistent.
	foreach ( (array) ( $package_to_hash['contents'] ?? array() ) as $item_id => $item ) {
		unset( $package_to_hash['contents'][ $item_id ]['data'] );
	}

	return 'wc_ship_' . md5( wp_json_encode( $package_to_hash ) . WC_Cache_Helper::get_transient_version( 'shipping' ) );
}