PluginProbe
Tiered Pricing Table for WooCommerce / 8.0.2
Tiered Pricing Table for WooCommerce v8.0.2
8.0.2 7.1.7 7.1.5 7.1.4 7.1.1 6.5.0 6.4.0 6.1.0 trunk 1.0 1.1 2.0 2.0.1 2.0.2 2.1 2.1.1 2.1.2 2.2.0 2.2.1 2.2.2 2.2.3 2.3.0 2.3.1 2.3.2 2.3.3 All 91 releases
tier-pricing-table / src / Addons / NonLoggedInUsers / Wholesale / Settings / Settings.php

Settings.php in Tiered Pricing Table for WooCommerce 8.0.2, at src/Addons/NonLoggedInUsers/Wholesale/Settings/Settings.php

150 lines 4.4 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php namespace TierPricingTable\Addons\NonLoggedInUsers\Wholesale\Settings;
2
3 use TierPricingTable\Settings\Settings as MainSettings;
4
5 /**
6 * Registers the "Wholesale" settings tab and reads its options.
7 */
8 class Settings {
9
10 const PREFIX = MainSettings::SETTINGS_PREFIX . 'wholesale_';
11
12 const APPROVAL_MANUAL = 'manual';
13 const APPROVAL_AUTO = 'auto';
14
15 public function __construct() {
16 new FormFieldsOption();
17
18 add_filter( 'tiered_pricing_table/settings/sections', function ( $sections ) {
19 $sections[] = new WholesaleSettingsSection();
20
21 return $sections;
22 }, 15 );
23
24 add_filter( 'tiered_pricing_table/settings/sections_order', function ( $order ) {
25 $order[ WholesaleSettingsSection::SLUG ] = 55;
26
27 return $order;
28 } );
29 }
30
31 public static function optionId( string $key ): string {
32 return self::PREFIX . $key;
33 }
34
35 protected static function get( string $key, $default = null ) {
36 return get_option( self::optionId( $key ), $default );
37 }
38
39 /**
40 * The feature is shipped switched off: the store owner turns it on here once the form page and the
41 * role prices are ready.
42 */
43 public static function isEnabled(): bool {
44 return 'yes' === self::get( 'enabled', 'no' );
45 }
46
47 public static function getRole(): string {
48 $role = (string) self::get( 'role', '' );
49
50 if ( '' === $role && function_exists( 'wp_roles' ) && wp_roles()->is_role( 'wholesale' ) ) {
51 $role = 'wholesale';
52 }
53
54 return $role;
55 }
56
57 public static function getApprovalMode(): string {
58 return self::APPROVAL_AUTO === self::get( 'approval', self::APPROVAL_MANUAL ) ? self::APPROVAL_AUTO : self::APPROVAL_MANUAL;
59 }
60
61 public static function isAutoApproval(): bool {
62 return self::APPROVAL_AUTO === self::getApprovalMode();
63 }
64
65 /**
66 * The application form's fields as built in the settings.
67 *
68 * @return array[] [ key, label, type, required, options ] each
69 */
70 public static function getFormFields(): array {
71 return FormFields::fromJson( self::get( 'form_fields', '' ) );
72 }
73
74 public static function getRegistrationPageId(): int {
75 return (int) self::get( 'registration_page', 0 );
76 }
77
78 public static function getRegistrationPageUrl(): string {
79 $pageId = self::getRegistrationPageId();
80
81 return $pageId ? (string) get_permalink( $pageId ) : '';
82 }
83
84 public static function getLoginRedirectPageId(): int {
85 return (int) self::get( 'login_redirect_page', 0 );
86 }
87
88 public static function showLoginFormLink(): bool {
89 return 'yes' === self::get( 'login_form_link', 'yes' );
90 }
91
92 public static function getLoginFormLinkText(): string {
93 return (string) self::get( 'login_form_link_text', __( 'Apply for a wholesale account', 'tier-pricing-table' ) );
94 }
95
96 public static function getFormTitle(): string {
97 return (string) self::get( 'form_title', __( 'Wholesale account', 'tier-pricing-table' ) );
98 }
99
100 public static function getFormIntro(): string {
101 return (string) self::get( 'form_intro',
102 __( 'Fill in the form below. We review every application and e-mail you as soon as your account is approved.',
103 'tier-pricing-table' ) );
104 }
105
106 public static function getSubmitText(): string {
107 return (string) self::get( 'submit_text', __( 'Apply for a wholesale account', 'tier-pricing-table' ) );
108 }
109
110 public static function getPendingMessage(): string {
111 return (string) self::get( 'pending_message',
112 __( 'Thank you! Your application has been received. We will e-mail you when it is approved.',
113 'tier-pricing-table' ) );
114 }
115
116 public static function getApprovedMessage(): string {
117 return (string) self::get( 'approved_message',
118 __( 'Your wholesale account is ready. You are logged in and see wholesale prices from now on.',
119 'tier-pricing-table' ) );
120 }
121
122 public static function getRejectedMessage(): string {
123 return (string) self::get( 'rejected_message',
124 __( 'We could not approve your wholesale application. Contact us if you have questions.',
125 'tier-pricing-table' ) );
126 }
127
128 public static function getTermsPageId(): int {
129 return (int) self::get( 'terms_page', 0 );
130 }
131
132 public static function useRecaptcha(): bool {
133 $keys = self::getRecaptchaKeys();
134
135 return 'yes' === self::get( 'recaptcha', 'no' ) && $keys['site'] && $keys['secret'];
136 }
137
138 /**
139 * The wholesale form's own reCAPTCHA v3 keys.
140 *
141 * @return array{site: string, secret: string}
142 */
143 public static function getRecaptchaKeys(): array {
144 return array(
145 'site' => trim( (string) self::get( 'recaptcha_site_key', '' ) ),
146 'secret' => trim( (string) self::get( 'recaptcha_secret_key', '' ) ),
147 );
148 }
149 }
150