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:
@@ -38,11 +38,6 @@ class Permissions {
|
||||
$has_wc = current_user_can('manage_woocommerce');
|
||||
$has_opts = current_user_can('manage_options');
|
||||
$result = $has_wc || $has_opts;
|
||||
error_log(sprintf('WooNooW Permissions: check_admin_permission() - WC:%s Options:%s Result:%s',
|
||||
$has_wc ? 'YES' : 'NO',
|
||||
$has_opts ? 'YES' : 'NO',
|
||||
$result ? 'ALLOWED' : 'DENIED'
|
||||
));
|
||||
return $result;
|
||||
}
|
||||
}
|
||||
@@ -447,6 +447,7 @@ class ProductsController {
|
||||
if (isset($data['description'])) $product->set_description(self::sanitize_textarea($data['description']));
|
||||
if (isset($data['short_description'])) $product->set_short_description(self::sanitize_textarea($data['short_description']));
|
||||
if (isset($data['sku'])) $product->set_sku(self::sanitize_text($data['sku']));
|
||||
|
||||
if (isset($data['regular_price'])) $product->set_regular_price(self::sanitize_number($data['regular_price']));
|
||||
if (isset($data['sale_price'])) $product->set_sale_price(self::sanitize_number($data['sale_price']));
|
||||
|
||||
@@ -800,15 +801,18 @@ class ProductsController {
|
||||
$value = $term ? $term->name : $value;
|
||||
}
|
||||
} else {
|
||||
// Custom attribute - WooCommerce stores as 'attribute_' + exact attribute name
|
||||
$meta_key = 'attribute_' . $attr_name;
|
||||
// Custom attribute - stored as lowercase in meta
|
||||
$meta_key = 'attribute_' . strtolower($attr_name);
|
||||
$value = get_post_meta($variation_id, $meta_key, true);
|
||||
|
||||
// Capitalize the attribute name for display
|
||||
// Capitalize the attribute name for display to match admin SPA
|
||||
$clean_name = ucfirst($attr_name);
|
||||
}
|
||||
|
||||
$formatted_attributes[$clean_name] = $value;
|
||||
// Only add if value exists
|
||||
if (!empty($value)) {
|
||||
$formatted_attributes[$clean_name] = $value;
|
||||
}
|
||||
}
|
||||
|
||||
$image_url = $image ? $image[0] : '';
|
||||
@@ -857,36 +861,106 @@ class ProductsController {
|
||||
* Save product variations
|
||||
*/
|
||||
private static function save_product_variations($product, $variations_data) {
|
||||
// Get existing variation IDs
|
||||
$existing_variation_ids = $product->get_children();
|
||||
$variations_to_keep = [];
|
||||
|
||||
foreach ($variations_data as $var_data) {
|
||||
if (isset($var_data['id']) && $var_data['id']) {
|
||||
// Update existing variation
|
||||
$variation = wc_get_product($var_data['id']);
|
||||
if (!$variation) continue;
|
||||
$variations_to_keep[] = $var_data['id'];
|
||||
} else {
|
||||
// Create new variation
|
||||
$variation = new WC_Product_Variation();
|
||||
$variation->set_parent_id($product->get_id());
|
||||
}
|
||||
|
||||
if ($variation) {
|
||||
if (isset($var_data['sku'])) $variation->set_sku($var_data['sku']);
|
||||
if (isset($var_data['regular_price'])) $variation->set_regular_price($var_data['regular_price']);
|
||||
if (isset($var_data['sale_price'])) $variation->set_sale_price($var_data['sale_price']);
|
||||
if (isset($var_data['stock_status'])) $variation->set_stock_status($var_data['stock_status']);
|
||||
if (isset($var_data['manage_stock'])) $variation->set_manage_stock($var_data['manage_stock']);
|
||||
if (isset($var_data['stock_quantity'])) $variation->set_stock_quantity($var_data['stock_quantity']);
|
||||
if (isset($var_data['attributes'])) $variation->set_attributes($var_data['attributes']);
|
||||
// Build attributes array
|
||||
$wc_attributes = [];
|
||||
if (isset($var_data['attributes']) && is_array($var_data['attributes'])) {
|
||||
$parent_attributes = $product->get_attributes();
|
||||
|
||||
// Handle image - support both image_id and image URL
|
||||
if (isset($var_data['image']) && !empty($var_data['image'])) {
|
||||
$image_id = attachment_url_to_postid($var_data['image']);
|
||||
if ($image_id) {
|
||||
$variation->set_image_id($image_id);
|
||||
foreach ($var_data['attributes'] as $display_name => $value) {
|
||||
if (empty($value)) continue;
|
||||
|
||||
foreach ($parent_attributes as $attr_name => $parent_attr) {
|
||||
if (!$parent_attr->get_variation()) continue;
|
||||
if (strcasecmp($display_name, $attr_name) === 0 || strcasecmp($display_name, ucfirst($attr_name)) === 0) {
|
||||
$wc_attributes[strtolower($attr_name)] = strtolower($value);
|
||||
break;
|
||||
}
|
||||
}
|
||||
} elseif (isset($var_data['image_id'])) {
|
||||
$variation->set_image_id($var_data['image_id']);
|
||||
}
|
||||
}
|
||||
|
||||
if (!empty($wc_attributes)) {
|
||||
$variation->set_attributes($wc_attributes);
|
||||
}
|
||||
|
||||
if (isset($var_data['sku'])) $variation->set_sku($var_data['sku']);
|
||||
|
||||
// Set prices - if not provided, use parent's price as fallback
|
||||
if (isset($var_data['regular_price']) && $var_data['regular_price'] !== '') {
|
||||
$variation->set_regular_price($var_data['regular_price']);
|
||||
} elseif (!$variation->get_regular_price()) {
|
||||
// Fallback to parent price if variation has no price
|
||||
$parent_price = $product->get_regular_price();
|
||||
if ($parent_price) {
|
||||
$variation->set_regular_price($parent_price);
|
||||
}
|
||||
}
|
||||
|
||||
if (isset($var_data['sale_price']) && $var_data['sale_price'] !== '') {
|
||||
$variation->set_sale_price($var_data['sale_price']);
|
||||
}
|
||||
|
||||
if (isset($var_data['stock_status'])) $variation->set_stock_status($var_data['stock_status']);
|
||||
if (isset($var_data['manage_stock'])) $variation->set_manage_stock($var_data['manage_stock']);
|
||||
if (isset($var_data['stock_quantity'])) $variation->set_stock_quantity($var_data['stock_quantity']);
|
||||
|
||||
if (isset($var_data['image']) && !empty($var_data['image'])) {
|
||||
$image_id = attachment_url_to_postid($var_data['image']);
|
||||
if ($image_id) $variation->set_image_id($image_id);
|
||||
} elseif (isset($var_data['image_id'])) {
|
||||
$variation->set_image_id($var_data['image_id']);
|
||||
}
|
||||
|
||||
// Save variation first
|
||||
$saved_id = $variation->save();
|
||||
$variations_to_keep[] = $saved_id;
|
||||
|
||||
// Manually save attributes using direct database insert
|
||||
if (!empty($wc_attributes)) {
|
||||
global $wpdb;
|
||||
|
||||
$variation->save();
|
||||
foreach ($wc_attributes as $attr_name => $attr_value) {
|
||||
$meta_key = 'attribute_' . $attr_name;
|
||||
|
||||
$wpdb->delete(
|
||||
$wpdb->postmeta,
|
||||
['post_id' => $saved_id, 'meta_key' => $meta_key],
|
||||
['%d', '%s']
|
||||
);
|
||||
|
||||
$wpdb->insert(
|
||||
$wpdb->postmeta,
|
||||
[
|
||||
'post_id' => $saved_id,
|
||||
'meta_key' => $meta_key,
|
||||
'meta_value' => $attr_value
|
||||
],
|
||||
['%d', '%s', '%s']
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Delete variations that are no longer in the list
|
||||
$variations_to_delete = array_diff($existing_variation_ids, $variations_to_keep);
|
||||
foreach ($variations_to_delete as $variation_id) {
|
||||
$variation_to_delete = wc_get_product($variation_id);
|
||||
if ($variation_to_delete) {
|
||||
$variation_to_delete->delete(true);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user