Agentic
4 months ago
BlockTemplates
4 weeks ago
EmailImprovements
1 year ago
EmailPreview
4 weeks ago
Emails
1 year ago
ImportExport
1 year ago
Logging
1 year ago
Marketing
2 years ago
Notes
4 weeks ago
Onboarding
5 months ago
Orders
4 weeks ago
ProductForm
2 years ago
ProductReviews
4 weeks ago
RemoteFreeExtensions
4 weeks ago
Schedulers
4 weeks ago
Settings
5 days ago
Suggestions
4 weeks ago
WCPayPromotion
10 months ago
ActivityPanels.php
3 years ago
Analytics.php
4 weeks ago
CategoryLookup.php
4 years ago
Coupons.php
1 year ago
CouponsMovedTrait.php
5 months ago
CustomerEffortScoreTracks.php
7 months ago
Events.php
2 months ago
FeaturePlugin.php
4 months ago
Homescreen.php
1 month ago
Loader.php
4 weeks ago
Marketing.php
1 year ago
Marketplace.php
5 months ago
MobileAppBanner.php
4 years ago
OrderMilestoneEasterEgg.php
4 weeks ago
RemoteInboxNotifications.php
3 years ago
Settings.php
5 days ago
ShippingLabelBanner.php
1 year ago
ShippingLabelBannerDisplayRules.php
1 year ago
SiteHealth.php
3 years ago
Survey.php
4 years ago
SystemStatusReport.php
1 year ago
Translations.php
1 year ago
WCAdminAssets.php
5 days ago
WCAdminSharedSettings.php
1 year ago
WCAdminUser.php
9 months ago
WcPayWelcomePage.php
1 year ago
CouponsMovedTrait.php
118 lines
| 1 | <?php |
| 2 | /** |
| 3 | * A Trait to help with managing the legacy coupon menu. |
| 4 | */ |
| 5 | |
| 6 | namespace Automattic\WooCommerce\Internal\Admin; |
| 7 | |
| 8 | use Automattic\WooCommerce\Admin\Features\Features; |
| 9 | |
| 10 | /** |
| 11 | * CouponsMovedTrait trait. |
| 12 | */ |
| 13 | trait CouponsMovedTrait { |
| 14 | |
| 15 | /** |
| 16 | * The GET query key for the legacy menu. |
| 17 | * |
| 18 | * @var string |
| 19 | */ |
| 20 | protected static $query_key = 'legacy_coupon_menu'; |
| 21 | |
| 22 | /** |
| 23 | * The key for storing an option in the DB. |
| 24 | * |
| 25 | * @var string |
| 26 | */ |
| 27 | protected static $option_key = 'wc_admin_show_legacy_coupon_menu'; |
| 28 | |
| 29 | /** |
| 30 | * Get the URL for the legacy coupon management. |
| 31 | * |
| 32 | * @return string The unescaped URL for the legacy coupon management page. |
| 33 | */ |
| 34 | protected static function get_legacy_coupon_url() { |
| 35 | return self::get_coupon_url( [ self::$query_key => true ] ); |
| 36 | } |
| 37 | |
| 38 | /** |
| 39 | * Get the URL for the coupon management page. |
| 40 | * |
| 41 | * @param array $args Additional URL query arguments. |
| 42 | * |
| 43 | * @return string |
| 44 | */ |
| 45 | protected static function get_coupon_url( $args = [] ) { |
| 46 | $args = array_merge( |
| 47 | [ |
| 48 | 'post_type' => 'shop_coupon', |
| 49 | ], |
| 50 | $args |
| 51 | ); |
| 52 | |
| 53 | return add_query_arg( $args, admin_url( 'edit.php' ) ); |
| 54 | } |
| 55 | |
| 56 | /** |
| 57 | * Get the new URL for managing coupons. |
| 58 | * |
| 59 | * @param string $page The management page. |
| 60 | * |
| 61 | * @return string |
| 62 | */ |
| 63 | protected static function get_management_url( $page ) { |
| 64 | $path = ''; |
| 65 | switch ( $page ) { |
| 66 | case 'coupon': |
| 67 | case 'coupons': |
| 68 | return self::get_coupon_url(); |
| 69 | |
| 70 | case 'marketing': |
| 71 | $path = self::get_marketing_path(); |
| 72 | break; |
| 73 | } |
| 74 | |
| 75 | return "wc-admin&path={$path}"; |
| 76 | } |
| 77 | |
| 78 | /** |
| 79 | * Get the WC Admin path for the marking page. |
| 80 | * |
| 81 | * @return string |
| 82 | */ |
| 83 | protected static function get_marketing_path() { |
| 84 | return '/marketing/overview'; |
| 85 | } |
| 86 | |
| 87 | /** |
| 88 | * Whether we should display the legacy coupon menu item. |
| 89 | * |
| 90 | * @return bool |
| 91 | */ |
| 92 | protected static function should_display_legacy_menu() { |
| 93 | /** |
| 94 | * Filter to determine whether to display the legacy coupon menu item. |
| 95 | * |
| 96 | * @since 10.5.0 |
| 97 | * |
| 98 | * @param bool $display Whether the menu should be displayed or not. |
| 99 | * @return bool |
| 100 | */ |
| 101 | return apply_filters( |
| 102 | 'wc_admin_show_legacy_coupon_menu', |
| 103 | ! Features::is_enabled( 'navigation' ) |
| 104 | ); |
| 105 | } |
| 106 | |
| 107 | /** |
| 108 | * Set whether we should display the legacy coupon menu item. |
| 109 | * |
| 110 | * @deprecated 10.5.0 No longer in use. |
| 111 | * |
| 112 | * @param bool $display Whether the menu should be displayed or not. |
| 113 | */ |
| 114 | protected static function display_legacy_menu( $display = false ) { |
| 115 | update_option( self::$option_key, $display ? 1 : 0 ); |
| 116 | } |
| 117 | } |
| 118 |