← All changes
|
src/Settings/Sections/GeneralSection/GeneralSection.php
+103
-15
6.1.0
→
8.0.2
View file →
| @@ -1,21 +1,25 @@ | ||
| 1 | 1 | <?php namespace TierPricingTable\Settings\Sections\GeneralSection; |
| 2 | 2 | |
| 3 | +use TierPricingTable\Addons\LayoutConfigurator\LayoutConfiguratorAddon; | |
| 3 | 4 | use TierPricingTable\Core\ServiceContainer; |
| 4 | -use TierPricingTable\Settings\Sections\GeneralSection\Subsections\CartOptionsSubsection; | |
| 5 | +use TierPricingTable\Settings\Sections\GeneralSection\Subsections\CalculationSubsection; | |
| 5 | 6 | use TierPricingTable\Settings\Sections\GeneralSection\Subsections\HiddenOptionsSubsection; |
| 6 | -use TierPricingTable\Settings\Sections\GeneralSection\Subsections\NonLoggedInUsersSubsection; | |
| 7 | -use TierPricingTable\Settings\Sections\GeneralSection\Subsections\UpsellsSubsection; | |
| 8 | -use TierPricingTable\Settings\Sections\GeneralSection\Subsections\CatalogPricesSubsection; | |
| 9 | 7 | use TierPricingTable\Settings\Sections\GeneralSection\Subsections\LayoutSubsection; |
| 10 | 8 | use TierPricingTable\Settings\Sections\GeneralSection\Subsections\ProductPagePriceSubsection; |
| 11 | -use TierPricingTable\Settings\Sections\GeneralSection\Subsections\SummarySubsection; | |
| 12 | -use TierPricingTable\Settings\Sections\GeneralSection\Subsections\YouSaveSubsection; | |
| 13 | 9 | use TierPricingTable\Settings\Sections\SectionAbstract; |
| 14 | 10 | use TierPricingTable\Settings\Settings; |
| 15 | 11 | |
| 16 | 12 | class GeneralSection extends SectionAbstract { |
| 17 | 13 | |
| 14 | + /** | |
| 15 | + * Value of the "Layout position" option meaning "I place the layout myself" (shortcode, block, widget). | |
| 16 | + * The layout configurator shows it as the automatic display being switched off. | |
| 17 | + */ | |
| 18 | + const NONE_POSITION = '____none____'; | |
| 19 | + | |
| 20 | + const DEFAULT_POSITION_HOOK = 'woocommerce_before_add_to_cart_button'; | |
| 21 | + | |
| 18 | 22 | public function getSettings() { |
| 19 | 23 | $settings = array(); |
| 20 | 24 | |
| 21 | 25 | foreach ( $this->getSubsections() as $subsection ) { |
| @@ -25,19 +29,21 @@ | ||
| 25 | 29 | return apply_filters( 'tiered_pricing_table/settings/general_settings', $settings ); |
| 26 | 30 | } |
| 27 | 31 | |
| 28 | 32 | protected function getSubsections() { |
| 29 | - return apply_filters( 'tiered_pricing_table/settings/general_subsections', array( | |
| 33 | + $subsections = array( | |
| 30 | 34 | HiddenOptionsSubsection::class, |
| 31 | 35 | LayoutSubsection::class, |
| 32 | - ProductPagePriceSubsection::class, | |
| 33 | - CatalogPricesSubsection::class, | |
| 34 | - CartOptionsSubsection::class, | |
| 35 | - YouSaveSubsection::class, | |
| 36 | - NonLoggedInUsersSubsection::class, | |
| 37 | - UpsellsSubsection::class, | |
| 38 | - SummarySubsection::class, | |
| 39 | - ) ); | |
| 36 | + ); | |
| 37 | + | |
| 38 | + // the layout configurator carries the product page price options while it is on | |
| 39 | + if ( ! LayoutConfiguratorAddon::isActive() ) { | |
| 40 | + $subsections[] = ProductPagePriceSubsection::class; | |
| 41 | + } | |
| 42 | + | |
| 43 | + $subsections[] = CalculationSubsection::class; | |
| 44 | + | |
| 45 | + return apply_filters( 'tiered_pricing_table/settings/general_subsections', $subsections ); | |
| 40 | 46 | } |
| 41 | 47 | |
| 42 | 48 | public static function deleteOptions() { |
| 43 | 49 | delete_option( Settings::SETTINGS_PREFIX . 'product_page_subsection' ); |
| @@ -97,8 +103,78 @@ | ||
| 97 | 103 | public function getName(): string { |
| 98 | 104 | return __( 'General', 'tier-pricing-table' ); |
| 99 | 105 | } |
| 100 | 106 | |
| 107 | + /** | |
| 108 | + * Whether the pricing layout is inserted on the product page automatically. Off means the merchant | |
| 109 | + * places it with a shortcode, block or widget; the plugin still renders a hidden wrapper so the | |
| 110 | + * live price updates keep working. | |
| 111 | + */ | |
| 112 | + public static function isAutomaticDisplayEnabled(): bool { | |
| 113 | + $settings = ServiceContainer::getInstance()->getSettings(); | |
| 114 | + | |
| 115 | + if ( self::NONE_POSITION === $settings->get( 'position_hook', self::DEFAULT_POSITION_HOOK ) ) { | |
| 116 | + return false; | |
| 117 | + } | |
| 118 | + | |
| 119 | + return 'yes' === $settings->get( 'display', 'yes' ); | |
| 120 | + } | |
| 121 | + | |
| 122 | + /** | |
| 123 | + * Hook the pricing layout is rendered on. A stored "none" position falls back to the default hook. | |
| 124 | + */ | |
| 125 | + public static function getPositionHook(): string { | |
| 126 | + $hook = (string) ServiceContainer::getInstance()->getSettings()->get( 'position_hook', self::DEFAULT_POSITION_HOOK ); | |
| 127 | + | |
| 128 | + return ( '' === $hook || self::NONE_POSITION === $hook ) ? self::DEFAULT_POSITION_HOOK : $hook; | |
| 129 | + } | |
| 130 | + | |
| 131 | + /** | |
| 132 | + * Design style choices per layout. | |
| 133 | + */ | |
| 134 | + /** | |
| 135 | + * Design styles withheld from shop and category pages, where the layouts sit in narrow grid cards: | |
| 136 | + * layout => styles. | |
| 137 | + */ | |
| 138 | + public static function getCatalogExcludedStyles(): array { | |
| 139 | + return (array) apply_filters( 'tiered_pricing_table/catalog/excluded_styles', array( | |
| 140 | + 'blocks' => array( 'style-8' ), | |
| 141 | + ) ); | |
| 142 | + } | |
| 143 | + | |
| 144 | + /** | |
| 145 | + * Design styles per layout. With $catalog, the styles withheld from shop and category pages are left out. | |
| 146 | + */ | |
| 147 | + public static function getStyleOptions( bool $catalog = false ): array { | |
| 148 | + $styles = function ( int $count ) { | |
| 149 | + $options = array( 'default' => __( 'Default', 'tier-pricing-table' ) ); | |
| 150 | + for ( $i = 1; $i <= $count; $i ++ ) { | |
| 151 | + /* translators: %d: style number */ | |
| 152 | + $options[ 'style-' . $i ] = sprintf( __( 'Style #%d', 'tier-pricing-table' ), $i ); | |
| 153 | + } | |
| 154 | + | |
| 155 | + return $options; | |
| 156 | + }; | |
| 157 | + | |
| 158 | + $options = array( | |
| 159 | + 'table' => $styles( 6 ), | |
| 160 | + 'blocks' => $styles( 8 ), | |
| 161 | + 'options' => $styles( 6 ), | |
| 162 | + 'dropdown' => $styles( 1 ), | |
| 163 | + 'plain-text' => $styles( 2 ), | |
| 164 | + ); | |
| 165 | + | |
| 166 | + if ( $catalog ) { | |
| 167 | + foreach ( self::getCatalogExcludedStyles() as $layout => $excluded ) { | |
| 168 | + if ( isset( $options[ $layout ] ) ) { | |
| 169 | + $options[ $layout ] = array_diff_key( $options[ $layout ], array_flip( (array) $excluded ) ); | |
| 170 | + } | |
| 171 | + } | |
| 172 | + } | |
| 173 | + | |
| 174 | + return $options; | |
| 175 | + } | |
| 176 | + | |
| 101 | 177 | public static function getOptionText() { |
| 102 | 178 | $default = __( '<strong>Buy {tp_quantity} pieces and save {tp_rounded_discount}%</strong>', |
| 103 | 179 | 'tier-pricing-table' ); |
| 104 | 180 | |
| @@ -146,6 +222,18 @@ | ||
| 146 | 222 | } |
| 147 | 223 | |
| 148 | 224 | public static function getPricingOptionsStyle(): string { |
| 149 | 225 | return ServiceContainer::getInstance()->getSettings()->get( 'pricing_options_style', 'default' ); |
| 226 | + } | |
| 227 | + | |
| 228 | + public static function getPricingTableStyle(): string { | |
| 229 | + return ServiceContainer::getInstance()->getSettings()->get( 'pricing_table_style', 'default' ); | |
| 230 | + } | |
| 231 | + | |
| 232 | + public static function getPricingDropdownStyle(): string { | |
| 233 | + return ServiceContainer::getInstance()->getSettings()->get( 'pricing_dropdown_style', 'default' ); | |
| 234 | + } | |
| 235 | + | |
| 236 | + public static function getPricingPlainTextStyle(): string { | |
| 237 | + return ServiceContainer::getInstance()->getSettings()->get( 'pricing_plain_text_style', 'default' ); | |
| 150 | 238 | } |
| 151 | 239 | } |