WC_Product_Variable_Data_Store_CPT::get_price_hash()
Create unique cache key based on the tax location (affects displayed/cached prices), product version and active price filters. DEVELOPERS should filter this hash if offering conditional pricing to keep it unique.
Method of the class: WC_Product_Variable_Data_Store_CPT{}
Hooks from the method
Return
String
.
Usage
// protected - for code of main (parent) or child class $result = $this->get_price_hash( $product, $for_display );
- $product(WC_Product) (required) (passed by reference — &)
- Product object.
- $for_display(true|false)
- If taxes should be calculated or not.
Default: false
Changelog
Since 3.0.0 | Introduced. |
WC_Product_Variable_Data_Store_CPT::get_price_hash() WC Product Variable Data Store CPT::get price hash code WC 9.4.2
protected function get_price_hash( &$product, $for_display = false ) { global $wp_filter; $price_hash = array( false ); if ( $for_display && wc_tax_enabled() ) { $price_hash = array( get_option( 'woocommerce_tax_display_shop', 'excl' ), WC_Tax::get_rates(), empty( WC()->customer ) ? false : WC()->customer->is_vat_exempt(), ); } $filter_names = array( 'woocommerce_variation_prices_price', 'woocommerce_variation_prices_regular_price', 'woocommerce_variation_prices_sale_price' ); foreach ( $filter_names as $filter_name ) { if ( ! empty( $wp_filter[ $filter_name ] ) ) { $price_hash[ $filter_name ] = array(); foreach ( $wp_filter[ $filter_name ] as $priority => $callbacks ) { $price_hash[ $filter_name ][] = array_values( wp_list_pluck( $callbacks, 'function' ) ); } } } return md5( wp_json_encode( apply_filters( 'woocommerce_get_variation_prices_hash', $price_hash, $product, $for_display ) ) ); }