Automattic\WooCommerce\Internal\Orders

CouponsController::add_coupon_discount_via_ajax()publicWC 1.0

Add order discount via Ajax.

{} Это метод класса: CouponsController{}

Хуков нет.

Возвращает

null. Ничего.

Использование

$CouponsController = new CouponsController();
$CouponsController->add_coupon_discount_via_ajax(): void;

Код CouponsController::add_coupon_discount_via_ajax() WC 6.9.4

public function add_coupon_discount_via_ajax(): void {
	check_ajax_referer( 'order-item', 'security' );

	if ( ! current_user_can( 'edit_shop_orders' ) ) {
		wp_die( -1 );
	}

	$response = array();

	try {
		$order = $this->add_coupon_discount( $_POST );

		ob_start();
		include __DIR__ . '/../../../includes/admin/meta-boxes/views/html-order-items.php';
		$response['html'] = ob_get_clean();
	} catch ( Exception $e ) {
		wp_send_json_error( array( 'error' => $e->getMessage() ) );
	}

	// wp_send_json_success must be outside the try block not to break phpunit tests.
	wp_send_json_success( $response );
}