| 1 |
<?php namespace TierPricingTable\Addons\NonLoggedInUsers\Visibility; |
| 2 |
|
| 3 |
use TierPricingTable\Settings\CustomOptions\TPTCheckboxListOption; |
| 4 |
use TierPricingTable\Settings\Settings; |
| 5 |
|
| 6 |
class VisibilitySettings { |
| 7 |
|
| 8 |
const PREFIX = Settings::SETTINGS_PREFIX . 'visibility_'; |
| 9 |
|
| 10 |
public static function optionId( string $key ): string { |
| 11 |
return self::PREFIX . $key; |
| 12 |
} |
| 13 |
|
| 14 |
protected static function get( string $key, $default = null ) { |
| 15 |
return get_option( self::optionId( $key ), $default ); |
| 16 |
} |
| 17 |
|
| 18 |
/** |
| 19 |
* Role-based catalog visibility: the "Who can see" rules on products and categories. Off by default, |
| 20 |
* so the product and category screens stay as they are for stores that do not need it. |
| 21 |
*/ |
| 22 |
public static function isEnabled(): bool { |
| 23 |
return 'yes' === self::get( 'enabled', 'no' ); |
| 24 |
} |
| 25 |
|
| 26 |
/** |
| 27 |
* Closed store: visitors who are not logged in are sent to the login page. |
| 28 |
*/ |
| 29 |
public static function isClosedStore(): bool { |
| 30 |
return 'yes' === self::get( 'closed_store', 'no' ); |
| 31 |
} |
| 32 |
|
| 33 |
/** |
| 34 |
* @return int[] page ids visitors may open while the store is closed (besides My Account and the wholesale registration page) |
| 35 |
*/ |
| 36 |
public static function getOpenPageIds(): array { |
| 37 |
return array_values( array_filter( array_map( 'intval', TPTCheckboxListOption::toArray( self::get( 'closed_store_pages', '' ) ) ) ) ); |
| 38 |
} |
| 39 |
|
| 40 |
/** |
| 41 |
* A guest who opens a hidden product or category: login page (yes) or a not-found page (no). |
| 42 |
*/ |
| 43 |
public static function redirectGuestsFromHidden(): bool { |
| 44 |
return 'yes' === self::get( 'hidden_redirect', 'yes' ); |
| 45 |
} |
| 46 |
} |
| 47 |
|