Skip to content

Commit 10b84cb

Browse files
TheSCREWEDSoftwareYehonalCopilot
authored
Do not allow smartstone skus to be added to cart without character selection (#168)
Current behavior (before this PR, as my mistake and lack of knowledge) smartstone can be added to cart without selecting a character (from the catologue of costumes or others from the smartstone), which leads people buying costumes and not getting them because there's no character associated. This fixes the current issue for the current implementation (for character unlock the service, if this get changed to account bound, we change smartstone impelemtnation then). This will redirect them to the page (of "add cart") and ask them to select the character This is hasn't be tested, and can't test it for now. And i tried submitting this fix on the same night of invesgiating, I couldn't update `acore-cms` within my `chormiecraft-cms` in my WSL, lack of linux and git together maybe. --------- Co-authored-by: Yehonal <[email protected]> Co-authored-by: Copilot <[email protected]>
1 parent cf9caee commit 10b84cb

File tree

1 file changed

+24
-0
lines changed

1 file changed

+24
-0
lines changed

src/acore-wp-plugin/src/Hooks/WooCommerce/Smartstone.php

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,30 @@ public static function init() {
2626
add_action('woocommerce_checkout_order_processed', self::sprefix() . 'checkout_order_processed', 20, 2);
2727
add_action('woocommerce_add_order_item_meta', self::sprefix() . 'add_order_item_meta', 1, 3);
2828
add_action('woocommerce_payment_complete', self::sprefix() . 'payment_complete');
29+
add_action('woocommerce_add_to_cart_validation', [__CLASS__, 'add_to_cart_validation'], 10, 5);
30+
}
31+
32+
// Validator for add to cart from external sources (no character selected) or logged in required from "CartValidation")
33+
public static function add_to_cart_validation($passed, $product_id, $quantity, $variation_id = null, $variations = null) {
34+
$product = $variation_id ? \wc_get_product($variation_id) : \wc_get_product($product_id);
35+
$sku = $product->get_sku();
36+
if (strpos($sku, 'smartstone') !== 0) {
37+
return $passed;
38+
}
39+
40+
$current_user = wp_get_current_user();
41+
if (!is_user_logged_in()) {
42+
\wc_add_notice(__('You must be logged in to buy it!', 'acore-wp-plugin'), 'error');
43+
return false;
44+
}
45+
46+
$guid = intval($_REQUEST['acore_char_sel'] ?? 0);
47+
if ($guid === 0) {
48+
\wc_add_notice(__('No character selected. Please select a character and try again.', 'acore-wp-plugin'), 'error');
49+
return false;
50+
}
51+
52+
return $passed;
2953
}
3054

3155
// LIST

0 commit comments

Comments
 (0)