← All changes
|
src/Addons/NonLoggedInUsers/NonLoggedInUsersAddon.php
+81
-4
6.4.0
→
8.0.2
View file →
| @@ -2,19 +2,44 @@ | ||
| 2 | 2 | |
| 3 | 3 | namespace TierPricingTable\Addons\NonLoggedInUsers; |
| 4 | 4 | |
| 5 | 5 | use TierPricingTable\Addons\AbstractAddon; |
| 6 | +use TierPricingTable\Addons\NonLoggedInUsers\Wholesale\CPT\ApplicationAdmin; | |
| 7 | +use TierPricingTable\Addons\NonLoggedInUsers\Wholesale\CPT\ApplicationCPT; | |
| 8 | +use TierPricingTable\Addons\NonLoggedInUsers\Wholesale\Emails\EmailsManager; | |
| 9 | +use TierPricingTable\Addons\NonLoggedInUsers\Wholesale\Frontend\RegistrationForm; | |
| 10 | +use TierPricingTable\Addons\NonLoggedInUsers\Wholesale\Services\LoginRedirect; | |
| 11 | +use TierPricingTable\Addons\NonLoggedInUsers\CartRules\CartRulesService; | |
| 12 | +use TierPricingTable\Addons\NonLoggedInUsers\CartRules\CartRulesSettings; | |
| 13 | +use TierPricingTable\Addons\NonLoggedInUsers\CartRules\CartRulesSubsection; | |
| 14 | +use TierPricingTable\Addons\NonLoggedInUsers\CartRules\PaymentMethodsSubsection; | |
| 15 | +use TierPricingTable\Addons\NonLoggedInUsers\CartRules\ShippingMethodsSubsection; | |
| 16 | +use TierPricingTable\Addons\NonLoggedInUsers\Visibility\Admin\CategoryListColumn; | |
| 17 | +use TierPricingTable\Addons\NonLoggedInUsers\Visibility\Admin\CategoryVisibilityFields; | |
| 18 | +use TierPricingTable\Addons\NonLoggedInUsers\Visibility\Admin\ProductListColumn; | |
| 19 | +use TierPricingTable\Addons\NonLoggedInUsers\Visibility\Admin\ProductListFilter; | |
| 20 | +use TierPricingTable\Addons\NonLoggedInUsers\Visibility\Admin\ProductVisibilityFields; | |
| 21 | +use TierPricingTable\Addons\NonLoggedInUsers\Visibility\ClosedStoreService; | |
| 22 | +use TierPricingTable\Addons\NonLoggedInUsers\Visibility\PrivateStoreSubsection; | |
| 23 | +use TierPricingTable\Addons\NonLoggedInUsers\Visibility\ProductVisibilityService; | |
| 24 | +use TierPricingTable\Addons\NonLoggedInUsers\Visibility\VisibilitySettings; | |
| 25 | +use TierPricingTable\Addons\NonLoggedInUsers\Wholesale\Settings\Settings as WholesaleSettings; | |
| 26 | +/** | |
| 27 | + * Wholesale & Guest Users: what visitors may see and buy, and how customers become wholesale | |
| 28 | + * customers (application form, approval queue, e-mails, login redirect). The slug is the one of the | |
| 29 | + * former "Non-Logged-In Users" module, so stores keep their on/off state. | |
| 30 | + */ | |
| 6 | 31 | class NonLoggedInUsersAddon extends AbstractAddon { |
| 7 | 32 | public function getName() { |
| 8 | - return __( 'Non-Logged-In Users', 'tier-pricing-table' ); | |
| 33 | + return __( 'Wholesale & Guest Users', 'tier-pricing-table' ); | |
| 9 | 34 | } |
| 10 | 35 | |
| 11 | 36 | public function getDescription() { |
| 12 | - return __( 'Hide prices or prevent purchasing for users who are not logged in.', 'tier-pricing-table' ); | |
| 37 | + return __( 'Hide prices or prevent purchasing for guests, close the store to visitors, show products and categories to selected roles only, set minimum orders and payment or shipping methods per role, and let customers apply for a wholesale account with an approval queue. Set up under the Wholesale tab.', 'tier-pricing-table' ); | |
| 13 | 38 | } |
| 14 | 39 | |
| 15 | 40 | public function getIcon() : string { |
| 16 | - return '<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24"><path d="M12 12c2.21 0 4-1.79 4-4s-1.79-4-4-4-4 1.79-4 4 1.79 4 4 4zm0 2c-2.67 0-8 1.34-8 4v2h16v-2c0-2.66-5.33-4-8-4z"/></svg>'; | |
| 41 | + return '<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24"><path d="M12 12c2.21 0 4-1.79 4-4s-1.79-4-4-4-4 1.79-4 4 1.79 4 4 4zm0 2c-2.67 0-8 1.34-8 4v2h9.5a6.5 6.5 0 0 1-.4-2H6c.2-.71 3.3-2 6-2 .35 0 .7.02 1.05.06.3-.7.72-1.34 1.23-1.89C13.55 14.06 12.77 14 12 14zm6.5 1a4.5 4.5 0 1 0 0 9 4.5 4.5 0 0 0 0-9zm-.62 6.62-2.12-2.12 1.06-1.06 1.06 1.06 2.3-2.3 1.06 1.06-3.36 3.36z"/></svg>'; | |
| 17 | 42 | } |
| 18 | 43 | |
| 19 | 44 | public function getSlug() { |
| 20 | 45 | return 'non-logged-in-users'; |
| @@ -20,15 +45,67 @@ | ||
| 20 | 45 | return 'non-logged-in-users'; |
| 21 | 46 | } |
| 22 | 47 | |
| 23 | 48 | public function run() { |
| 49 | + // the Wholesale tab: registration settings first, the guest options as its last group | |
| 50 | + new WholesaleSettings(); | |
| 51 | + new CartRulesSettings(); | |
| 52 | + add_filter( 'tiered_pricing_table/settings/wholesale_subsections', array($this, 'addSettingsSubsection') ); | |
| 53 | + // the private store is part of the free plugin: the closed store checks its own switch on every | |
| 54 | + // request; catalog visibility by role is an opt-in, so the product and category screens stay | |
| 55 | + // simple by default | |
| 56 | + new ClosedStoreService(); | |
| 57 | + if ( VisibilitySettings::isEnabled() ) { | |
| 58 | + new ProductVisibilityService(); | |
| 59 | + if ( is_admin() ) { | |
| 60 | + new ProductVisibilityFields(); | |
| 61 | + new CategoryVisibilityFields(); | |
| 62 | + new ProductListColumn(); | |
| 63 | + new ProductListFilter(); | |
| 64 | + new CategoryListColumn(); | |
| 65 | + } | |
| 66 | + } | |
| 67 | + // wholesale registration is part of the free plugin too | |
| 68 | + if ( WholesaleSettings::isEnabled() ) { | |
| 69 | + new ApplicationCPT(); | |
| 70 | + new ApplicationAdmin(); | |
| 71 | + new EmailsManager(); | |
| 72 | + new RegistrationForm(); | |
| 73 | + new LoginRedirect(); | |
| 74 | + } else { | |
| 75 | + // the shortcode stays known, so a page that carries it explains itself to the store owner | |
| 76 | + add_shortcode( RegistrationForm::SHORTCODE, array($this, 'renderDisabledNote') ); | |
| 77 | + } | |
| 78 | + return; | |
| 79 | + // premium: the guest options and the cart rules | |
| 24 | 80 | add_action( 'init', function () { |
| 81 | + $this->getContainer()->initService( NonLoggedInUsersService::class ); | |
| 25 | 82 | } ); |
| 26 | - add_filter( 'tiered_pricing_table/settings/general_subsections', array($this, 'addSettingsSubsection') ); | |
| 83 | + if ( CartRulesSettings::isEnabled() ) { | |
| 84 | + new CartRulesService(); | |
| 85 | + } | |
| 27 | 86 | } |
| 28 | 87 | |
| 29 | 88 | public function addSettingsSubsection( $subsections ) { |
| 89 | + // the private store is free; the cart rules and the guest options are premium and are shown | |
| 90 | + // locked in the free version (PremiumSettingsManager) | |
| 91 | + $subsections[] = PrivateStoreSubsection::class; | |
| 92 | + $subsections[] = CartRulesSubsection::class; | |
| 93 | + $subsections[] = PaymentMethodsSubsection::class; | |
| 94 | + $subsections[] = ShippingMethodsSubsection::class; | |
| 30 | 95 | $subsections[] = NonLoggedInUsersSubsection::class; |
| 31 | 96 | return $subsections; |
| 97 | + } | |
| 98 | + | |
| 99 | + public function renderDisabledNote() : string { | |
| 100 | + if ( !current_user_can( 'manage_woocommerce' ) ) { | |
| 101 | + return ''; | |
| 102 | + } | |
| 103 | + $url = admin_url( 'admin.php?page=wc-settings&tab=tiered_pricing_table_settings§ion=wholesale' ); | |
| 104 | + return '<p class="tpt-wholesale-disabled-note"><em>' . sprintf( | |
| 105 | + /* translators: %s: link to the settings */ | |
| 106 | + esc_html__( 'Wholesale registration is switched off. Enable it under %s. Only shop managers see this note.', 'tier-pricing-table' ), | |
| 107 | + '<a href="' . esc_url( $url ) . '">' . esc_html__( 'Tiered Pricing → Wholesale', 'tier-pricing-table' ) . '</a>' | |
| 108 | + ) . '</em></p>'; | |
| 32 | 109 | } |
| 33 | 110 | |
| 34 | 111 | } |