tier-pricing-table
/
src
/
Settings
/
Sections
/
GeneralSection
/
Subsections
/
ProductPagePriceSubsection.php
ProductPagePriceSubsection.php in Tiered Pricing Table for WooCommerce 8.0.2, at src/Settings/Sections/GeneralSection/Subsections/ProductPagePriceSubsection.php
| 1 | <?php namespace TierPricingTable\Settings\Sections\GeneralSection\Subsections; |
| 2 | |
| 3 | use TierPricingTable\Core\ServiceContainer; |
| 4 | use TierPricingTable\Settings\CustomOptions\TPTDisplayType; |
| 5 | use TierPricingTable\Settings\CustomOptions\TPTSwitchOption; |
| 6 | use TierPricingTable\Settings\Sections\SubsectionAbstract; |
| 7 | use TierPricingTable\Settings\Settings; |
| 8 | |
| 9 | class ProductPagePriceSubsection extends SubsectionAbstract { |
| 10 | |
| 11 | public function getTitle(): string { |
| 12 | return __( 'Single Product Page Pricing', 'tier-pricing-table' ); |
| 13 | } |
| 14 | |
| 15 | public function getDescription(): string { |
| 16 | return __( 'Manage how tiered prices are displayed and behave on single product pages.', |
| 17 | 'tier-pricing-table' ); |
| 18 | } |
| 19 | |
| 20 | public function getSlug(): string { |
| 21 | return 'product_page_price'; |
| 22 | } |
| 23 | |
| 24 | public function getSettings(): array { |
| 25 | $price = function ( $amount ) { |
| 26 | return wp_strip_all_tags( wc_price( $amount ) ); |
| 27 | }; |
| 28 | |
| 29 | return array( |
| 30 | array( |
| 31 | 'title' => __( 'Price display format', 'tier-pricing-table' ), |
| 32 | 'id' => Settings::SETTINGS_PREFIX . 'product_page_price_format', |
| 33 | 'type' => TPTDisplayType::FIELD_TYPE, |
| 34 | 'options' => array( |
| 35 | 'same_as_catalog' => __( 'Match Shop & Categories display (price range or lowest price)', 'tier-pricing-table' ), |
| 36 | 'custom' => __( 'Actual price for selected quantity', 'tier-pricing-table' ), |
| 37 | ), |
| 38 | 'descriptions' => array( |
| 39 | /* translators: %s: example price */ |
| 40 | 'same_as_catalog' => sprintf( __( 'e.g. "From %s" or a price range, as on the shop page', 'tier-pricing-table' ), $price( 10 ) ), |
| 41 | /* translators: %s: example price */ |
| 42 | 'custom' => sprintf( __( 'e.g. %s when 50 pieces are selected', 'tier-pricing-table' ), $price( 12 ) ), |
| 43 | ), |
| 44 | 'default' => ServiceContainer::getInstance()->getSettings()->get( 'tiered_price_at_product_page', |
| 45 | 'no' ) === 'yes' ? 'same_as_catalog' : 'custom', |
| 46 | ), |
| 47 | array( |
| 48 | 'title' => __( 'Update price on quantity change', 'tier-pricing-table' ), |
| 49 | 'id' => Settings::SETTINGS_PREFIX . 'update_price_on_product_page', |
| 50 | 'type' => TPTSwitchOption::FIELD_TYPE, |
| 51 | 'default' => 'yes', |
| 52 | 'desc' => __( 'Automatically update the main product price whenever a customer changes the quantity input.', |
| 53 | 'tier-pricing-table' ), |
| 54 | ), |
| 55 | array( |
| 56 | 'title' => __( 'Show original price crossed out', 'tier-pricing-table' ), |
| 57 | 'id' => Settings::SETTINGS_PREFIX . 'show_tiered_price_as_discount', |
| 58 | 'type' => TPTSwitchOption::FIELD_TYPE, |
| 59 | 'default' => 'yes', |
| 60 | 'desc' => __( 'Cross out the regular price and show the discounted tiered price next to it when a higher quantity is selected.', |
| 61 | 'tier-pricing-table' ), |
| 62 | ), |
| 63 | array( |
| 64 | 'title' => __( 'Show total price (Price × Quantity)', 'tier-pricing-table' ), |
| 65 | 'id' => Settings::SETTINGS_PREFIX . 'show_total_price', |
| 66 | 'type' => TPTSwitchOption::FIELD_TYPE, |
| 67 | 'default' => 'no', |
| 68 | 'desc' => __( 'Multiply the main product price by the selected quantity instead of showing the per-item price.', |
| 69 | 'tier-pricing-table' ), |
| 70 | ), |
| 71 | array( |
| 72 | 'title' => __( 'Show total price for non-tiered products', 'tier-pricing-table' ), |
| 73 | 'id' => Settings::SETTINGS_PREFIX . 'show_total_price_non_tiered', |
| 74 | 'type' => TPTSwitchOption::FIELD_TYPE, |
| 75 | 'default' => 'no', |
| 76 | 'desc' => __( 'Multiply the price by quantity even if the product has no tiered pricing rules.', |
| 77 | 'tier-pricing-table' ), |
| 78 | ), |
| 79 | ); |
| 80 | } |
| 81 | |
| 82 | public static function getFormatPriceType() { |
| 83 | |
| 84 | $settings = ServiceContainer::getInstance()->getSettings(); |
| 85 | |
| 86 | $default = $settings->get( 'tiered_price_at_product_page', 'no' ) === 'yes' ? 'same_as_catalog' : 'custom'; |
| 87 | |
| 88 | return $settings->get( 'product_page_price_format', $default ); |
| 89 | } |
| 90 | } |
| 91 |