403Webshell
Server IP : 62.60.133.156  /  Your IP : 216.73.217.51
Web Server : LiteSpeed
System : Linux linux24.centraldnserver.com 4.18.0-553.141.2.lve.el8.x86_64 #1 SMP Wed Jul 8 16:10:02 UTC 2026 x86_64
User : mimradmin ( 1166)
PHP Version : 7.4.33
Disable Function : show_source, system, shell_exec, passthru, exec, popen, proc_open
MySQL : OFF |  cURL : ON |  WGET : ON |  Perl : ON |  Python : ON |  Sudo : OFF |  Pkexec : OFF
Directory :  /proc/thread-self/cwd/wp-content/plugins/woocommerce/src/Api/Mutations/Coupons/

Upload File :
current_dir [ Writeable] document_root [ Writeable]

 

Command :


[ Back ]     

Current File : /proc/thread-self/cwd/wp-content/plugins/woocommerce/src/Api/Mutations/Coupons/CreateCoupon.php
<?php

declare(strict_types=1);

namespace Automattic\WooCommerce\Api\Mutations\Coupons;

use Automattic\WooCommerce\Api\Attributes\Description;
use Automattic\WooCommerce\Api\Attributes\RequiredCapability;
use Automattic\WooCommerce\Api\InputTypes\Coupons\CreateCouponInput;
use Automattic\WooCommerce\Api\Utils\Coupons\CouponMapper;
use Automattic\WooCommerce\Api\Types\Coupons\Coupon;

/**
 * Mutation to create a new coupon.
 */
#[Description( 'Create a new coupon.' )]
#[RequiredCapability( 'manage_woocommerce' )]
class CreateCoupon {
	/**
	 * Execute the mutation.
	 *
	 * @param CreateCouponInput $input The coupon creation data.
	 * @return Coupon
	 */
	public function execute(
		#[Description( 'Data for the new coupon.' )]
		CreateCouponInput $input,
	): Coupon {
		$wc_coupon = new \WC_Coupon();
		$wc_coupon->set_code( $input->code );

		foreach ( array( 'description', 'amount', 'date_expires', 'individual_use', 'product_ids', 'excluded_product_ids', 'usage_limit', 'usage_limit_per_user', 'limit_usage_to_x_items', 'free_shipping', 'product_categories', 'excluded_product_categories', 'exclude_sale_items', 'minimum_amount', 'maximum_amount', 'email_restrictions' ) as $field ) {
			if ( null !== $input->$field ) {
				$wc_coupon->{"set_{$field}"}( $input->$field );
			}
		}

		if ( null !== $input->discount_type ) {
			$wc_coupon->set_discount_type( $input->discount_type->value );
		}
		if ( null !== $input->status ) {
			$wc_coupon->set_status( $input->status->value );
		}

		$wc_coupon->save();

		return CouponMapper::from_wc_coupon( $wc_coupon );
	}
}

Youez - 2016 - github.com/yon3zu