fix: WP-Admin CSS conflicts and add-to-cart redirect
- Fix CSS conflicts between WP-Admin and SPA (radio buttons, chart text) - Add Tailwind important selector scoped to #woonoow-admin-app - Remove overly aggressive inline SVG styles from Assets.php - Add targeted WordPress admin CSS overrides in index.css - Fix add-to-cart redirect to use woocommerce_add_to_cart_redirect filter - Let WooCommerce handle cart operations natively for proper session management - Remove duplicate tailwind.config.cjs
This commit is contained in:
@@ -66,5 +66,64 @@ class Bootstrap {
|
||||
MailQueue::init();
|
||||
WooEmailOverride::init();
|
||||
OrderStore::init();
|
||||
|
||||
// Initialize cart for REST API requests
|
||||
add_action('woocommerce_init', [self::class, 'init_cart_for_rest_api']);
|
||||
|
||||
// Load custom variation attributes for WooCommerce admin
|
||||
add_action('woocommerce_product_variation_object_read', [self::class, 'load_variation_attributes']);
|
||||
}
|
||||
|
||||
/**
|
||||
* Properly initialize WooCommerce cart for REST API requests
|
||||
* This is the recommended approach per WooCommerce core team
|
||||
*/
|
||||
public static function init_cart_for_rest_api() {
|
||||
// Only load cart for REST API requests
|
||||
if (!WC()->is_rest_api_request()) {
|
||||
return;
|
||||
}
|
||||
|
||||
// Load frontend includes (required for cart)
|
||||
WC()->frontend_includes();
|
||||
|
||||
// Load cart using WooCommerce's official method
|
||||
if (null === WC()->cart && function_exists('wc_load_cart')) {
|
||||
wc_load_cart();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Load custom variation attributes from post meta for WooCommerce admin
|
||||
* This ensures WooCommerce's native admin displays custom attributes correctly
|
||||
*/
|
||||
public static function load_variation_attributes($variation) {
|
||||
if (!$variation instanceof \WC_Product_Variation) {
|
||||
return;
|
||||
}
|
||||
|
||||
$parent = wc_get_product($variation->get_parent_id());
|
||||
if (!$parent) {
|
||||
return;
|
||||
}
|
||||
|
||||
$attributes = [];
|
||||
foreach ($parent->get_attributes() as $attr_name => $attribute) {
|
||||
if (!$attribute->get_variation()) {
|
||||
continue;
|
||||
}
|
||||
|
||||
// Read from post meta (stored as lowercase)
|
||||
$meta_key = 'attribute_' . strtolower($attr_name);
|
||||
$value = get_post_meta($variation->get_id(), $meta_key, true);
|
||||
|
||||
if (!empty($value)) {
|
||||
$attributes[strtolower($attr_name)] = $value;
|
||||
}
|
||||
}
|
||||
|
||||
if (!empty($attributes)) {
|
||||
$variation->set_attributes($attributes);
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user