← All changes
|
src/Addons/LayoutConfigurator/LayoutConfigurator.php
+45
-3
8.0.2
→
8.1.0
View file →
| @@ -84,9 +84,11 @@ | ||
| 84 | 84 | 'you_save_enabled' => 'yes', |
| 85 | 85 | 'you_save_consider_sale_price' => 'yes', |
| 86 | 86 | 'you_save_non_tiered' => 'no', |
| 87 | 87 | 'you_save_template' => '', |
| 88 | - 'you_save_text_color' => '#FF0000', | |
| 88 | + 'you_save_text_color' => '', // empty: the active tier colour | |
| 89 | + 'you_save_style' => 'text', | |
| 90 | + 'you_save_position' => 'price', | |
| 89 | 91 | ); |
| 90 | 92 | |
| 91 | 93 | const YOU_SAVE_ADDON_SLUG = 'you-save'; |
| 92 | 94 | |
| @@ -255,9 +257,9 @@ | ||
| 255 | 257 | return implode( ',', array_filter( array_map( 'intval', \TierPricingTable\Settings\CustomOptions\TPTCheckboxListOption::toArray( $value ) ) ) ); |
| 256 | 258 | } ); |
| 257 | 259 | |
| 258 | 260 | // colours: a hex colour, or the option's default |
| 259 | - foreach ( array( 'selected_quantity_color' => '#3858e9', 'tooltip_color' => '#3858e9', 'you_save_text_color' => '#FF0000', 'cart_upsell_color' => '#059669', 'shop_loop_display_selected_quantity_color' => '#3858e9' ) as $id => $default ) { | |
| 261 | + foreach ( array( 'selected_quantity_color' => '#3858e9', 'tooltip_color' => '#3858e9', 'cart_upsell_color' => '#059669', 'shop_loop_display_selected_quantity_color' => '#3858e9' ) as $id => $default ) { | |
| 260 | 262 | add_filter( 'woocommerce_admin_settings_sanitize_option_' . self::getOptionId( $id ), function ( $value ) use ( $default ) { |
| 261 | 263 | $color = is_string( $value ) ? sanitize_hex_color( trim( $value ) ) : null; |
| 262 | 264 | |
| 263 | 265 | return $color ? $color : $default; |
| @@ -264,9 +266,9 @@ | ||
| 264 | 266 | } ); |
| 265 | 267 | } |
| 266 | 268 | |
| 267 | 269 | // optional colours: a hex colour, or empty (the design style's own colours) |
| 268 | - foreach ( array( 'discount_badge_color', 'shop_loop_display_discount_badge_color', 'shop_loop_display_badge_color' ) as $id ) { | |
| 270 | + foreach ( array( 'discount_badge_color', 'shop_loop_display_discount_badge_color', 'shop_loop_display_badge_color', 'you_save_text_color' ) as $id ) { | |
| 269 | 271 | add_filter( 'woocommerce_admin_settings_sanitize_option_' . self::getOptionId( $id ), function ( $value ) { |
| 270 | 272 | $color = is_string( $value ) ? sanitize_hex_color( trim( $value ) ) : null; |
| 271 | 273 | |
| 272 | 274 | return $color ? $color : ''; |
| @@ -293,8 +295,9 @@ | ||
| 293 | 295 | */ |
| 294 | 296 | const CHOICE_OPTIONS = array( |
| 295 | 297 | 'shop_loop_display_badge_position', |
| 296 | 298 | 'shop_loop_display_scope', |
| 299 | + 'you_save_style', 'you_save_position', | |
| 297 | 300 | 'display_type', 'pricing_table_style', 'pricing_blocks_style', 'pricing_options_style', 'pricing_dropdown_style', 'pricing_plain_text_style', |
| 298 | 301 | 'quantity_type', 'tiers_order', 'discount_format', 'product_page_price_format', 'position_hook', 'summary_type', 'tiered_price_at_catalog_type', |
| 299 | 302 | 'shop_loop_display_layout', 'shop_loop_display_pricing_table_style', 'shop_loop_display_pricing_blocks_style', 'shop_loop_display_pricing_options_style', |
| 300 | 303 | 'shop_loop_display_pricing_dropdown_style', 'shop_loop_display_pricing_plain_text_style', 'shop_loop_display_quantity_type', 'shop_loop_display_tiers_order', |
| @@ -318,8 +321,10 @@ | ||
| 318 | 321 | 'quantity_type' => array( 'range', 'static' ), |
| 319 | 322 | 'tiers_order' => array( 'asc', 'desc' ), |
| 320 | 323 | 'discount_format' => array( 'percentage', 'amount', 'both' ), |
| 321 | 324 | 'product_page_price_format' => array( 'custom', 'same_as_catalog' ), |
| 325 | + 'you_save_style' => array( 'text', 'pill', 'outline' ), | |
| 326 | + 'you_save_position' => array( 'price', 'before_add_to_cart', 'after_table' ), | |
| 322 | 327 | 'shop_loop_display_badge_position' => array( 'top-left', 'top-right' ), |
| 323 | 328 | 'shop_loop_display_scope' => array( 'everywhere', 'selected' ), |
| 324 | 329 | 'position_hook' => array_merge( array_keys( self::getPositionOptions() ), array( GeneralSection::NONE_POSITION ) ), |
| 325 | 330 | 'shop_loop_display_layout' => array_values( array_diff( $layouts, array( 'tooltip' ) ) ), |
| @@ -662,8 +667,32 @@ | ||
| 662 | 667 | return GeneralSection::getStyleOptions(); |
| 663 | 668 | } |
| 664 | 669 | |
| 665 | 670 | /** |
| 671 | + * The product-page preview for the stored values, rendered with the page so the first paint needs | |
| 672 | + * no request: the current layout plus the sibling layouts the preview prefetches, and the extras. | |
| 673 | + */ | |
| 674 | + protected function getInitialPreview( LayoutPreview $preview ): ?array { | |
| 675 | + try { | |
| 676 | + $values = $preview->getStoredValues(); | |
| 677 | + $fragments = array(); | |
| 678 | + foreach ( array_keys( LayoutPreview::KINDS ) as $kind ) { | |
| 679 | + $fragments[ $kind ] = $preview->render( $kind, $values, 'product-page' ); | |
| 680 | + } | |
| 681 | + | |
| 682 | + return array( | |
| 683 | + 'fragments' => $fragments, | |
| 684 | + 'extras' => array( | |
| 685 | + 'catalogPrice' => $preview->renderCatalogPrice( $values ), | |
| 686 | + 'summary' => $preview->renderSummary( $values ), | |
| 687 | + ), | |
| 688 | + ); | |
| 689 | + } catch ( \Throwable $e ) { | |
| 690 | + return null; // the app falls back to a request | |
| 691 | + } | |
| 692 | + } | |
| 693 | + | |
| 694 | + /** | |
| 666 | 695 | * Configuration handed to the app. |
| 667 | 696 | */ |
| 668 | 697 | public function getConfig(): array { |
| 669 | 698 | $values = array(); |
| @@ -759,9 +788,22 @@ | ||
| 759 | 788 | 'badge_template' => array( 'tp_max_discount', 'tp_lowest_price', 'tp_lowest_quantity', 'tp_max_saving' ), |
| 760 | 789 | ), |
| 761 | 790 | 'placeholder' => function_exists( 'wc_placeholder_img_src' ) ? wc_placeholder_img_src( 'woocommerce_single' ) : '', |
| 762 | 791 | 'youSave' => self::isYouSaveAvailable(), |
| 792 | + 'youSaveOptions' => array( | |
| 793 | + 'styles' => array( | |
| 794 | + 'text' => __( 'Text', 'tier-pricing-table' ), | |
| 795 | + 'pill' => __( 'Pill', 'tier-pricing-table' ), | |
| 796 | + 'outline' => __( 'Outlined', 'tier-pricing-table' ), | |
| 797 | + ), | |
| 798 | + 'positions' => array( | |
| 799 | + 'price' => __( 'Under the price', 'tier-pricing-table' ), | |
| 800 | + 'before_add_to_cart' => __( 'Above the add-to-cart button', 'tier-pricing-table' ), | |
| 801 | + 'after_table' => __( 'After the pricing layout', 'tier-pricing-table' ), | |
| 802 | + ), | |
| 803 | + ), | |
| 763 | 804 | 'samples' => $samples, |
| 805 | + 'initial' => $this->getInitialPreview( $preview ), | |
| 764 | 806 | 'summary' => self::isSummaryAvailable() ? array( |
| 765 | 807 | 'positions' => self::getPositionOptions(), |
| 766 | 808 | 'types' => array( |
| 767 | 809 | 'detailed' => __( 'Detailed', 'tier-pricing-table' ), |