Automattic\WooCommerce\Internal\Orders

CouponsController::add_coupon_discount_via_ajax()publicWC 1.0

Add order discount via Ajax.

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

Хуков нет.

Возвращает

null. Ничего (null).

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

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

Код CouponsController::add_coupon_discount_via_ajax() WC 9.3.3

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();

		ob_start();
		$notes = wc_get_order_notes( array( 'order_id' => $order->get_id() ) );
		include __DIR__ . '/../../../includes/admin/meta-boxes/views/html-order-notes.php';
		$response['notes_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 );
}