WC_Shipping::get_package_hash
Generate the shipping-rate cache hash for a package.
Method of the class: WC_Shipping{}
Hooks from the method
Returns
String.
Usage
// private - for code of main (parent) class only $result = $this->get_package_hash( $package_to_hash ): string;
- $package_to_hash(array) (required)
- Package of cart items.
WC_Shipping::get_package_hash() WC Shipping::get package hash code WC 11.0.0
private function get_package_hash( array $package_to_hash ): string {
/**
* 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' ) );
}