| @@ -12,8 +12,30 @@ | ||
| 12 | 12 | * |
| 13 | 13 | * @package TierPricingTable\Managers |
| 14 | 14 | */ |
| 15 | 15 | class FormatPriceManager { |
| 16 | + /** | |
| 17 | + * Cache key for a formatted price. | |
| 18 | + * | |
| 19 | + * The formatted output depends on the display type and formatting flags, and several callers (for example, SEO | |
| 20 | + * integrations building schema or title variables) request a plain, prefix-less version early in the request. | |
| 21 | + * Keying by these arguments keeps each variant cached separately instead of letting the first caller win. | |
| 22 | + * | |
| 23 | + * @param string $displayType | |
| 24 | + * @param array $args | |
| 25 | + * | |
| 26 | + * @return string | |
| 27 | + */ | |
| 28 | + protected static function getPriceCacheKey( string $displayType, array $args ) : string { | |
| 29 | + return 'price_html_' . md5( wp_json_encode( array( | |
| 30 | + $displayType, | |
| 31 | + (bool) $args['html'], | |
| 32 | + (bool) $args['for_display'], | |
| 33 | + (bool) $args['with_suffix'], | |
| 34 | + (bool) $args['with_lowest_prefix'] | |
| 35 | + ) ) ); | |
| 36 | + } | |
| 37 | + | |
| 16 | 38 | public static function getFormattedPrice( WC_Product $product, array $args = array() ) : ?string { |
| 17 | 39 | $args = wp_parse_args( $args, array( |
| 18 | 40 | 'html' => true, |
| 19 | 41 | 'display_type' => null, |