Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion css/cleantalk-admin.min.css

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

45 changes: 45 additions & 0 deletions css/src/cleantalk-admin.css
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,51 @@
.apbct-details-spam-order-button {
color: gray;
}

/* WooCommerce orders list alike view of the spam orders table.
The order column has no width, so it takes all the space left. */
.wp-list-table.wc_spam_orders .column-ct_order_date,
.wp-list-table.wc_spam_orders .column-ct_status,
.wp-list-table.wc_spam_orders .column-ct_total {
width: 15%;
}

.wp-list-table.wc_spam_orders td {
vertical-align: middle;
}

.wp-list-table.wc_spam_orders .apbct-order-view {
color: #2271b1;
text-decoration: none;
}

.wp-list-table.wc_spam_orders .apbct-order-view:hover {
color: #135e96;
}

.apbct-order-status {
display: inline-flex;
line-height: 2.5em;
color: #454545;
background: #e5e5e5;
border-radius: 4px;
border-bottom: 1px solid rgba(0, 0, 0, .05);
margin: -.25em 0;
cursor: inherit !important;
white-space: nowrap;
max-width: 100%;
}

.apbct-order-status > span {
margin: 0 1em;
overflow: hidden;
text-overflow: ellipsis;
}

.apbct-order-status--spam {
background: #eba3a3;
color: #570000;
}
.ct-modal-buttons {
display: flex;
align-items: center;
Expand Down
93 changes: 74 additions & 19 deletions lib/Cleantalk/Antispam/IntegrationsByClass/Woocommerce.php
Original file line number Diff line number Diff line change
Expand Up @@ -177,6 +177,11 @@ public function checkoutCheck($_data, $errors)
{
global $apbct, $cleantalk_executed;

if ( ! $apbct->settings['data__wc_store_blocked_orders'] ) {
// The checkout is left to WooCommerce as is: no check, no blocked order to store.
return;
}
Comment on lines +180 to +183

if ( count($errors->errors) ) {
return;
}
Expand Down Expand Up @@ -230,14 +235,10 @@ public function checkoutCheck($_data, $errors)
ct_hash($ct_result->id);

if ( $ct_result->allow == 0 ) {
if ( $apbct->settings['data__wc_store_blocked_orders'] ) {
$this->storeBlockedOrder();
}
$this->handleBlockedOrder();
wp_send_json(array(
'result' => 'failure',
'messages' => "<ul class=\"woocommerce-error\"><li>" . $ct_result->comment . "</li></ul>",
'refresh' => 'false',
'reload' => 'false'
'result' => 'success',
'redirect' => $this->getBlockedOrderRedirectUrl(),
));
}
}
Expand All @@ -252,6 +253,11 @@ public function checkoutCheckFromRest($order)
{
global $apbct, $cleantalk_executed;

if ( ! $apbct->settings['data__wc_store_blocked_orders'] ) {
// The checkout is left to WooCommerce as is: no check, no blocked order to store.
return;
}

if ( is_null($order) || ! ($order instanceof \WC_Order) ) {
return;
}
Expand Down Expand Up @@ -286,34 +292,83 @@ public function checkoutCheckFromRest($order)
ct_hash($ct_result->id);

if ( $ct_result->allow == 0 ) {
if ( $apbct->settings['data__wc_store_blocked_orders'] ) {
$this->storeBlockedOrder();
}
$response = $this->getStoreApiPassedResponse($order);

$this->handleBlockedOrder();

if ( $order->get_status() === 'pending' || $order->get_status() === 'checkout-draft' ) {
if ( function_exists('wc_release_stock_for_order') ) {
wc_release_stock_for_order($order);
}

try {
$order->delete(true);
} catch (\Exception $e) {
error_log('Error deleting order: ' . $e->getMessage());
}
}

$response = [
'code' => 'woocommerce_store_api_checkout_order_processed',
'message' => $ct_result->comment,
'data' => [
'status' => 403
]
];

if ( ! headers_sent() ) {
http_response_code(403);
header('Content-Type: application/json; charset=utf-8');
}
die(json_encode($response));
}
}
}

/**
* Common actions for an order blocked as spam.
*
* @return void
* @psalm-suppress UndefinedFunction
*/
private function handleBlockedOrder()
{
$this->storeBlockedOrder();

if ( function_exists('wc') && ! is_null(wc()->cart) ) {
wc()->cart->empty_cart();
}
}
Comment on lines +325 to +332

/**
* URL of the page shown to the visitor whose order was blocked.
*
* @return string
* @psalm-suppress UndefinedFunction
*/
private function getBlockedOrderRedirectUrl()
{
return wc_get_endpoint_url('order-received', '', wc_get_checkout_url());
}
Comment on lines +340 to +343

/**
* Response for the Store API checkout route imitating a passed checkout.
*
* @param \WC_Order $order
*
* @return array
* @psalm-suppress UndefinedClass, UndefinedFunction
*/
private function getStoreApiPassedResponse($order)
{
return array(
'order_id' => $order->get_id(),
'status' => $order->get_status(),
'order_key' => $order->get_order_key(),
'customer_note' => $order->get_customer_note(),
'customer_id' => $order->get_customer_id(),
'billing_address' => $order->get_address('billing'),
'shipping_address' => $order->get_address('shipping'),
'payment_method' => $order->get_payment_method(),
'payment_result' => array(
'payment_status' => 'success',
'payment_details' => array(),
'redirect_url' => $this->getBlockedOrderRedirectUrl(),
),
);
}

/**
* @return void
* @psalm-suppress UndefinedFunction
Expand Down
2 changes: 1 addition & 1 deletion lib/Cleantalk/ApbctWP/State.php
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ class State extends \Cleantalk\Common\State
'data__email_decoder_obfuscation_custom_text' => '',
'data__email_decoder_encode_phone_numbers' => 0,
'data__email_decoder_encode_email_addresses' => 1,
'data__wc_store_blocked_orders' => 0,
'data__wc_store_blocked_orders' => 1,

// Exclusions
// Send to the cloud some excepted requests
Expand Down
Loading
Loading