tier-pricing-table
/
src
/
Addons
/
NonLoggedInUsers
/
Wholesale
/
Settings
/
WholesaleSettingsSection.php
WholesaleSettingsSection.php in Tiered Pricing Table for WooCommerce 8.0.2, at src/Addons/NonLoggedInUsers/Wholesale/Settings/WholesaleSettingsSection.php
| 1 | <?php namespace TierPricingTable\Addons\NonLoggedInUsers\Wholesale\Settings; |
| 2 | |
| 3 | use TierPricingTable\Addons\NonLoggedInUsers\Wholesale\CPT\ApplicationCPT; |
| 4 | use TierPricingTable\Settings\CustomOptions\TPTSwitchOption; |
| 5 | use TierPricingTable\Settings\Sections\SectionAbstract; |
| 6 | |
| 7 | class WholesaleSettingsSection extends SectionAbstract { |
| 8 | |
| 9 | const SLUG = 'wholesale'; |
| 10 | |
| 11 | public function getName(): string { |
| 12 | return __( 'Wholesale', 'tier-pricing-table' ); |
| 13 | } |
| 14 | |
| 15 | public function getSlug(): string { |
| 16 | return self::SLUG; |
| 17 | } |
| 18 | |
| 19 | public function getSettings(): array { |
| 20 | $premium = tpt_fs()->can_use_premium_code__premium_only(); |
| 21 | $settings = array(); |
| 22 | |
| 23 | $settings[] = array( |
| 24 | 'title' => __( 'Wholesale registration', 'tier-pricing-table' ), |
| 25 | 'desc' => $this->getIntro( $premium ), |
| 26 | 'id' => Settings::optionId( 'section_registration' ), |
| 27 | 'type' => 'title', |
| 28 | ); |
| 29 | |
| 30 | $settings = array_merge( $settings, array( |
| 31 | array( |
| 32 | 'title' => __( 'Enable wholesale registration', 'tier-pricing-table' ), |
| 33 | 'id' => Settings::optionId( 'enabled' ), |
| 34 | 'type' => TPTSwitchOption::FIELD_TYPE, |
| 35 | 'default' => 'no', |
| 36 | 'desc' => __( 'Publishes the application form, the approval queue and the e-mails. Switch it on to see and set up the options below; nothing goes live until you save.', |
| 37 | 'tier-pricing-table' ), |
| 38 | ), |
| 39 | array( |
| 40 | 'title' => __( 'Wholesale role', 'tier-pricing-table' ), |
| 41 | 'id' => Settings::optionId( 'role' ), |
| 42 | 'type' => 'select', |
| 43 | 'class' => 'wc-enhanced-select', |
| 44 | 'options' => $this->getRoleOptions(), |
| 45 | 'default' => Settings::getRole(), |
| 46 | 'desc' => sprintf( |
| 47 | /* translators: %s: link to Roles Management */ |
| 48 | __( 'The role approved applicants get. Create roles under %s, then set up prices for the role on products or in a global pricing rule.', 'tier-pricing-table' ), |
| 49 | '<a href="' . esc_url( admin_url( 'admin.php?page=wc-settings&tab=tiered_pricing_table_settings§ion=advanced#roles' ) ) . '">' . esc_html__( 'Advanced → Roles Management', 'tier-pricing-table' ) . '</a>' |
| 50 | ), |
| 51 | 'desc_tip' => false, |
| 52 | ), |
| 53 | array( |
| 54 | 'title' => __( 'Approval', 'tier-pricing-table' ), |
| 55 | 'id' => Settings::optionId( 'approval' ), |
| 56 | 'type' => 'select', |
| 57 | 'options' => array( |
| 58 | Settings::APPROVAL_MANUAL => __( 'Review every application (approve or reject by hand)', |
| 59 | 'tier-pricing-table' ), |
| 60 | Settings::APPROVAL_AUTO => __( 'Approve automatically', 'tier-pricing-table' ), |
| 61 | ), |
| 62 | 'default' => Settings::APPROVAL_MANUAL, |
| 63 | 'desc' => __( 'Pending applicants keep the regular customer role until they are approved.', |
| 64 | 'tier-pricing-table' ), |
| 65 | ), |
| 66 | array( |
| 67 | 'title' => __( 'Registration page', 'tier-pricing-table' ), |
| 68 | 'id' => Settings::optionId( 'registration_page' ), |
| 69 | 'type' => 'single_select_page', |
| 70 | 'class' => 'wc-enhanced-select', |
| 71 | 'default' => '', |
| 72 | 'desc' => sprintf( |
| 73 | /* translators: %s: shortcode */ |
| 74 | __( 'The page that contains the %s shortcode. Used for the link on the login form and in e-mails.', |
| 75 | 'tier-pricing-table' ), |
| 76 | '<code>[tiered_pricing_wholesale_registration]</code>' |
| 77 | ), |
| 78 | ), |
| 79 | array( |
| 80 | 'title' => __( 'After login, send wholesale customers to', 'tier-pricing-table' ), |
| 81 | 'id' => Settings::optionId( 'login_redirect_page' ), |
| 82 | 'type' => 'single_select_page', |
| 83 | 'class' => 'wc-enhanced-select', |
| 84 | 'default' => '', |
| 85 | 'desc' => __( 'Optional. A wholesale landing page, a catalog category or the shop. Leave empty to keep the default My Account redirect.', |
| 86 | 'tier-pricing-table' ), |
| 87 | ), |
| 88 | array( |
| 89 | 'title' => __( 'Link on the login form', 'tier-pricing-table' ), |
| 90 | 'id' => Settings::optionId( 'login_form_link' ), |
| 91 | 'type' => TPTSwitchOption::FIELD_TYPE, |
| 92 | 'default' => 'yes', |
| 93 | 'desc' => __( 'Show an "Apply for a wholesale account" link under the My Account login form. Needs the registration page above.', |
| 94 | 'tier-pricing-table' ), |
| 95 | ), |
| 96 | array( |
| 97 | 'title' => __( 'Link text', 'tier-pricing-table' ), |
| 98 | 'id' => Settings::optionId( 'login_form_link_text' ), |
| 99 | 'type' => 'text', |
| 100 | 'default' => __( 'Apply for a wholesale account', 'tier-pricing-table' ), |
| 101 | ), |
| 102 | array( |
| 103 | 'type' => 'sectionend', |
| 104 | 'id' => Settings::optionId( 'section_registration' ), |
| 105 | ), |
| 106 | |
| 107 | array( |
| 108 | 'title' => __( 'Application form', 'tier-pricing-table' ), |
| 109 | 'desc' => __( 'Name, e-mail and (when WooCommerce does not generate passwords) a password are always asked. Build the rest of the form here.', |
| 110 | 'tier-pricing-table' ), |
| 111 | 'id' => Settings::optionId( 'section_form' ), |
| 112 | 'type' => 'title', |
| 113 | ), |
| 114 | array( |
| 115 | 'title' => __( 'Fields', 'tier-pricing-table' ), |
| 116 | 'id' => Settings::optionId( 'form_fields' ), |
| 117 | 'type' => FormFieldsOption::FIELD_TYPE, |
| 118 | 'desc' => __( 'Company, Phone and Website are copied to the customer account; every other field is stored with the application and shown in the queue and the e-mails. A dropdown takes one option per line.', |
| 119 | 'tier-pricing-table' ), |
| 120 | ), |
| 121 | array( |
| 122 | 'title' => __( 'Terms page', 'tier-pricing-table' ), |
| 123 | 'id' => Settings::optionId( 'terms_page' ), |
| 124 | 'type' => 'single_select_page', |
| 125 | 'class' => 'wc-enhanced-select', |
| 126 | 'default' => '', |
| 127 | 'desc' => __( 'Optional. Adds an "I agree to the terms" checkbox linking to this page.', |
| 128 | 'tier-pricing-table' ), |
| 129 | ), |
| 130 | array( |
| 131 | 'title' => __( 'Form title', 'tier-pricing-table' ), |
| 132 | 'id' => Settings::optionId( 'form_title' ), |
| 133 | 'type' => 'text', |
| 134 | 'default' => __( 'Wholesale account', 'tier-pricing-table' ), |
| 135 | ), |
| 136 | array( |
| 137 | 'title' => __( 'Intro text', 'tier-pricing-table' ), |
| 138 | 'id' => Settings::optionId( 'form_intro' ), |
| 139 | 'type' => 'textarea', |
| 140 | 'css' => 'min-height: 70px;', |
| 141 | 'default' => __( 'Fill in the form below. We review every application and e-mail you as soon as your account is approved.', |
| 142 | 'tier-pricing-table' ), |
| 143 | ), |
| 144 | array( |
| 145 | 'title' => __( 'Button text', 'tier-pricing-table' ), |
| 146 | 'id' => Settings::optionId( 'submit_text' ), |
| 147 | 'type' => 'text', |
| 148 | 'default' => __( 'Apply for a wholesale account', 'tier-pricing-table' ), |
| 149 | ), |
| 150 | array( |
| 151 | 'type' => 'sectionend', |
| 152 | 'id' => Settings::optionId( 'section_form' ), |
| 153 | ), |
| 154 | |
| 155 | array( |
| 156 | 'title' => __( 'Spam protection', 'tier-pricing-table' ), |
| 157 | 'desc' => sprintf( |
| 158 | /* translators: %s: link to the Google reCAPTCHA admin console */ |
| 159 | __( 'The form already has a honeypot. For reCAPTCHA v3, create a key pair of type "Score based (v3)" in the %s and enter it here; these keys are separate from the Request a Quote keys.', 'tier-pricing-table' ), |
| 160 | '<a href="https://www.google.com/recaptcha/admin" target="_blank" rel="noopener">' . esc_html__( 'reCAPTCHA admin console', 'tier-pricing-table' ) . '</a>' |
| 161 | ), |
| 162 | 'id' => Settings::optionId( 'section_spam' ), |
| 163 | 'type' => 'title', |
| 164 | ), |
| 165 | array( |
| 166 | 'title' => __( 'reCAPTCHA v3', 'tier-pricing-table' ), |
| 167 | 'id' => Settings::optionId( 'recaptcha' ), |
| 168 | 'type' => TPTSwitchOption::FIELD_TYPE, |
| 169 | 'default' => 'no', |
| 170 | 'desc' => $this->getRecaptchaDescription(), |
| 171 | ), |
| 172 | array( |
| 173 | 'title' => __( 'Site key', 'tier-pricing-table' ), |
| 174 | 'id' => Settings::optionId( 'recaptcha_site_key' ), |
| 175 | 'type' => 'text', |
| 176 | 'default' => '', |
| 177 | 'css' => 'min-width: 400px;', |
| 178 | 'placeholder' => '6L…', |
| 179 | ), |
| 180 | array( |
| 181 | 'title' => __( 'Secret key', 'tier-pricing-table' ), |
| 182 | 'id' => Settings::optionId( 'recaptcha_secret_key' ), |
| 183 | 'type' => 'password', |
| 184 | 'default' => '', |
| 185 | 'css' => 'min-width: 400px;', |
| 186 | 'placeholder' => '6L…', |
| 187 | 'desc' => __( 'Kept on the server; used only to verify submissions with Google.', 'tier-pricing-table' ), |
| 188 | ), |
| 189 | array( |
| 190 | 'type' => 'sectionend', |
| 191 | 'id' => Settings::optionId( 'section_spam' ), |
| 192 | ), |
| 193 | |
| 194 | array( |
| 195 | 'title' => __( 'Messages', 'tier-pricing-table' ), |
| 196 | 'desc' => __( 'Shown on the registration page. The e-mails are edited under WooCommerce → Settings → Emails.', |
| 197 | 'tier-pricing-table' ), |
| 198 | 'id' => Settings::optionId( 'section_messages' ), |
| 199 | 'type' => 'title', |
| 200 | ), |
| 201 | array( |
| 202 | 'title' => __( 'Application received', 'tier-pricing-table' ), |
| 203 | 'id' => Settings::optionId( 'pending_message' ), |
| 204 | 'type' => 'textarea', |
| 205 | 'css' => 'min-height: 70px;', |
| 206 | 'default' => __( 'Thank you! Your application has been received. We will e-mail you when it is approved.', |
| 207 | 'tier-pricing-table' ), |
| 208 | ), |
| 209 | array( |
| 210 | 'title' => __( 'Approved', 'tier-pricing-table' ), |
| 211 | 'id' => Settings::optionId( 'approved_message' ), |
| 212 | 'type' => 'textarea', |
| 213 | 'css' => 'min-height: 70px;', |
| 214 | 'default' => __( 'Your wholesale account is ready. You are logged in and see wholesale prices from now on.', |
| 215 | 'tier-pricing-table' ), |
| 216 | 'desc' => __( 'Shown after automatic approval, and to approved customers who open the registration page.', |
| 217 | 'tier-pricing-table' ), |
| 218 | ), |
| 219 | array( |
| 220 | 'title' => __( 'Rejected', 'tier-pricing-table' ), |
| 221 | 'id' => Settings::optionId( 'rejected_message' ), |
| 222 | 'type' => 'textarea', |
| 223 | 'css' => 'min-height: 70px;', |
| 224 | 'default' => __( 'We could not approve your wholesale application. Contact us if you have questions.', |
| 225 | 'tier-pricing-table' ), |
| 226 | ), |
| 227 | array( |
| 228 | 'type' => 'sectionend', |
| 229 | 'id' => Settings::optionId( 'section_messages' ), |
| 230 | ), |
| 231 | ) ); |
| 232 | |
| 233 | // groups other modules put on this tab after the registration settings: the guest options, for one |
| 234 | foreach ( (array) apply_filters( 'tiered_pricing_table/settings/wholesale_subsections', array() ) as $subsection ) { |
| 235 | if ( class_exists( $subsection ) ) { |
| 236 | $settings = array_merge( $settings, ( new $subsection() )->getWrappedSettings() ); |
| 237 | } |
| 238 | } |
| 239 | |
| 240 | return $settings; |
| 241 | } |
| 242 | |
| 243 | protected function getIntro( bool $premium ): string { |
| 244 | $intro = __( 'Customers apply for a wholesale account with the registration form; you approve them under WooCommerce → Wholesale Applications, and they get the wholesale role with its prices.', |
| 245 | 'tier-pricing-table' ); |
| 246 | |
| 247 | // the queue (its post type and menu) only exists while the feature is on |
| 248 | if ( ! Settings::isEnabled() ) { |
| 249 | return $intro . ' ' . esc_html__( 'The feature is off until you enable it below.', 'tier-pricing-table' ); |
| 250 | } |
| 251 | |
| 252 | $queueUrl = admin_url( 'edit.php?post_type=' . ApplicationCPT::POST_TYPE ); |
| 253 | |
| 254 | return $intro . ' <a href="' . esc_url( $queueUrl ) . '">' . esc_html__( 'Open the applications queue', 'tier-pricing-table' ) . '</a>'; |
| 255 | } |
| 256 | |
| 257 | protected function getRoleOptions(): array { |
| 258 | $options = array( '' => __( 'Select a role…', 'tier-pricing-table' ) ); |
| 259 | |
| 260 | if ( ! function_exists( 'wp_roles' ) ) { |
| 261 | return $options; |
| 262 | } |
| 263 | |
| 264 | foreach ( wp_roles()->roles as $key => $role ) { |
| 265 | if ( in_array( $key, array( 'administrator', 'editor', 'author', 'contributor', 'shop_manager' ), true ) ) { |
| 266 | continue; |
| 267 | } |
| 268 | |
| 269 | $options[ $key ] = translate_user_role( $role['name'] ); |
| 270 | } |
| 271 | |
| 272 | return $options; |
| 273 | } |
| 274 | |
| 275 | |
| 276 | protected function getRecaptchaDescription(): string { |
| 277 | $keys = Settings::getRecaptchaKeys(); |
| 278 | |
| 279 | if ( $keys['site'] && $keys['secret'] ) { |
| 280 | return __( 'Checks every submission with Google reCAPTCHA v3 and rejects low scores.', 'tier-pricing-table' ); |
| 281 | } |
| 282 | |
| 283 | return __( 'Needs the site key and the secret key below; the switch does nothing until both are set.', |
| 284 | 'tier-pricing-table' ); |
| 285 | } |
| 286 | } |
| 287 |