PHP 8.2.31
Preview: Coupons.php Size: 2.86 KB
/home/nshryvcy/radiantskinclinics.org/wp-content/plugins/woocommerce/src/Internal/Admin/Coupons.php

<?php
/**
 * WooCommerce Marketing > Coupons.
 */

namespace Automattic\WooCommerce\Internal\Admin;

use Automattic\WooCommerce\Admin\Features\Features;
use Automattic\WooCommerce\Admin\PageController;

/**
 * Contains backend logic for the Coupons feature.
 */
class Coupons {

	use CouponsMovedTrait;

	/**
	 * Class instance.
	 *
	 * @var Coupons instance
	 */
	protected static $instance = null;

	/**
	 * Get class instance.
	 */
	public static function get_instance() {
		if ( ! self::$instance ) {
			self::$instance = new self();
		}
		return self::$instance;
	}

	/**
	 * Hook into WooCommerce.
	 */
	public function __construct() {
		if ( ! is_admin() ) {
			return;
		}

		// If the main marketing feature is disabled, don't modify coupon behavior.
		if ( ! Features::is_enabled( 'marketing' ) ) {
			return;
		}

		// Only support coupon modifications if coupons are enabled.
		if ( ! wc_coupons_enabled() ) {
			return;
		}

		add_action( 'admin_enqueue_scripts', array( $this, 'maybe_add_marketing_coupon_script' ) );
		add_action( 'woocommerce_register_post_type_shop_coupon', array( $this, 'move_coupons' ) );
		add_action( 'admin_head', array( $this, 'fix_coupon_menu_highlight' ), 99 );
		add_action( 'admin_menu', array( $this, 'maybe_add_coupon_menu_redirect' ) );
	}

	/**
	 * Maybe add menu item back in original spot to help people transition
	 */
	public function maybe_add_coupon_menu_redirect() {
		if ( ! $this->should_display_legacy_menu() ) {
			return;
		}

		add_submenu_page(
			'woocommerce',
			__( 'Coupons', 'woocommerce' ),
			__( 'Coupons', 'woocommerce' ),
			'manage_options',
			'coupons-moved',
			array( $this, 'coupon_menu_moved' )
		);
	}

	/**
	 * Call back for transition menu item
	 */
	public function coupon_menu_moved() {
		wp_safe_redirect( $this->get_legacy_coupon_url(), 301 );
		exit();
	}

	/**
	 * Modify registered post type shop_coupon
	 *
	 * @param array $args Array of post type parameters.
	 *
	 * @return array the filtered parameters.
	 */
	public function move_coupons( $args ) {
		$args['show_in_menu'] = current_user_can( 'manage_woocommerce' ) ? 'woocommerce-marketing' : true;
		return $args;
	}

	/**
	 * Undo WC modifications to $parent_file for 'shop_coupon'
	 */
	public function fix_coupon_menu_highlight() {
		global $parent_file, $post_type;

		if ( $post_type === 'shop_coupon' ) {
			$parent_file = 'woocommerce-marketing'; // phpcs:ignore WordPress.WP.GlobalVariablesOverride
		}
	}

	/**
	 * Maybe add our wc-admin coupon scripts if viewing coupon pages
	 */
	public function maybe_add_marketing_coupon_script() {
		$curent_screen = PageController::get_instance()->get_current_page();
		if ( ! isset( $curent_screen['id'] ) || $curent_screen['id'] !== 'woocommerce-coupons' ) {
			return;
		}

		WCAdminAssets::register_style( 'marketing-coupons', 'style' );
		WCAdminAssets::register_script( 'wp-admin-scripts', 'marketing-coupons', true );
	}
}

Directory Contents

Dirs: 18 × Files: 25

Name Size Perms Modified Actions
Agentic DIR
- drwxr-xr-x 2026-05-29 02:43:21
Edit Download
- drwxr-xr-x 2026-05-29 02:43:21
Edit Download
- drwxr-xr-x 2026-05-29 02:43:21
Edit Download
- drwxr-xr-x 2026-05-29 02:43:21
Edit Download
Emails DIR
- drwxr-xr-x 2026-05-29 02:43:21
Edit Download
- drwxr-xr-x 2026-05-29 02:43:21
Edit Download
Logging DIR
- drwxr-xr-x 2026-05-29 02:43:21
Edit Download
Marketing DIR
- drwxr-xr-x 2026-05-29 02:43:21
Edit Download
Notes DIR
- drwxr-xr-x 2026-05-29 02:43:21
Edit Download
- drwxr-xr-x 2026-05-29 02:43:21
Edit Download
Orders DIR
- drwxr-xr-x 2026-05-29 02:43:21
Edit Download
- drwxr-xr-x 2026-05-29 02:43:21
Edit Download
- drwxr-xr-x 2026-05-29 02:43:21
Edit Download
- drwxr-xr-x 2026-05-29 02:43:21
Edit Download
- drwxr-xr-x 2026-05-29 02:43:21
Edit Download
Settings DIR
- drwxr-xr-x 2026-05-29 02:43:21
Edit Download
- drwxr-xr-x 2026-05-29 02:43:21
Edit Download
- drwxr-xr-x 2026-05-29 02:43:21
Edit Download
1.58 KB lrw-r--r-- 2022-08-24 02:07:06
Edit Download
11.78 KB lrw-r--r-- 2026-01-19 14:46:18
Edit Download
7.99 KB lrw-r--r-- 2022-04-20 06:50:54
Edit Download
2.86 KB lrw-r--r-- 2024-11-14 01:17:00
Edit Download
2.41 KB lrw-r--r-- 2026-01-19 14:46:18
Edit Download
17.65 KB lrw-r--r-- 2025-11-24 23:10:10
Edit Download
8.54 KB lrw-r--r-- 2026-05-05 14:26:50
Edit Download
6.77 KB lrw-r--r-- 2026-02-23 17:58:34
Edit Download
8.70 KB lrw-r--r-- 2026-05-11 17:17:08
Edit Download
19.18 KB lrw-r--r-- 2025-05-12 21:07:28
Edit Download
6.29 KB lrw-r--r-- 2024-11-14 01:17:00
Edit Download
3.48 KB lrw-r--r-- 2026-01-19 14:46:18
Edit Download
956 B lrw-r--r-- 2022-04-20 06:50:54
Edit Download
932 B lrw-r--r-- 2023-03-21 20:45:06
Edit Download
14.61 KB lrw-r--r-- 2026-05-05 14:26:50
Edit Download
4.67 KB lrw-r--r-- 2024-09-23 20:44:04
Edit Download
3.63 KB lrw-r--r-- 2024-09-04 20:34:26
Edit Download
2.31 KB lrw-r--r-- 2023-02-22 07:17:34
Edit Download
768 B lrw-r--r-- 2022-04-20 06:50:54
Edit Download
5.85 KB lrw-r--r-- 2025-05-12 21:07:28
Edit Download
11.66 KB lrw-r--r-- 2024-11-14 01:17:00
Edit Download
17.74 KB lrw-r--r-- 2026-05-05 14:26:50
Edit Download
2.08 KB lrw-r--r-- 2025-04-22 15:40:34
Edit Download
5.26 KB lrw-r--r-- 2025-10-06 17:56:06
Edit Download
6.33 KB lrw-r--r-- 2025-06-23 19:46:28
Edit Download

If ZipArchive is unavailable, a .tar will be created (no compression).