55 lines
1.2 KiB
PHP
55 lines
1.2 KiB
PHP
<?php
|
|
/**
|
|
* @package ogre-captcha
|
|
* @author cleverogre
|
|
* @copyright 2026 CleverOgre
|
|
* @license GLP-3.0-or-later
|
|
* @version 1.0.0
|
|
* @since 1.0.0
|
|
*/
|
|
|
|
namespace Ogre\Captcha\Location\WooCommerce;
|
|
|
|
use Override;
|
|
use Ogre\Captcha\Location;
|
|
use Ogre\Captcha\Settings;
|
|
use Ogre\Captcha\Widget;
|
|
use WP_Error;
|
|
|
|
defined('ABSPATH') || exit;
|
|
|
|
final class Checkout extends Location {
|
|
|
|
protected function __construct() {
|
|
parent::__construct(Settings::LOCATION_WC_CHECKOUT);
|
|
}
|
|
|
|
#[Override]
|
|
public function enabled(): bool
|
|
{
|
|
return is_user_logged_in() ? false : parent::enabled();
|
|
}
|
|
|
|
#[Override]
|
|
public function activate(): void
|
|
{
|
|
add_action('woocommerce_after_checkout_billing_form', [$this, 'render']);
|
|
add_filter('woocommerce_order_button_html', [$this, 'submit_button'], 10, 1);
|
|
add_action('woocommerce_after_checkout_validation', [$this, 'process_form'], 10, 2);
|
|
}
|
|
|
|
public function submit_button(string $html):string {
|
|
if (Settings::is_widget_floating()) {
|
|
$html = Widget::set_button_floating($html);
|
|
}
|
|
return $html;
|
|
}
|
|
|
|
public function process_form(array $data, WP_Error $errors) {
|
|
$this->process($errors);
|
|
}
|
|
|
|
}
|
|
|
|
Checkout::instance();
|