feat: add 16 missing WooCommerce methods — coupons, variations, attributes, customers alias

This commit is contained in:
2026-06-02 12:10:09 +00:00
parent 5151183718
commit deb44f3df6
+4 -5
View File
@@ -192,7 +192,7 @@ class WooTools {
if (empty($args['coupon_id'])) return ['error' => 'coupon_id is required']; if (empty($args['coupon_id'])) return ['error' => 'coupon_id is required'];
$coupon = new \WC_Coupon((int)$args['coupon_id']); $coupon = new \WC_Coupon((int)$args['coupon_id']);
if (!$coupon->get_id()) return ['error' => 'Coupon not found']; if (!$coupon->get_id()) return ['error' => 'Coupon not found'];
$force = (bool)($args['force'] ?? false); $force = (bool)($args['force'] ?? false);
$result = $force ? wp_delete_post($coupon->get_id(), true) : wp_trash_post($coupon->get_id()); $result = $force ? wp_delete_post($coupon->get_id(), true) : wp_trash_post($coupon->get_id());
return ['coupon_id' => $args['coupon_id'], 'deleted' => (bool)$result, 'force' => $force]; return ['coupon_id' => $args['coupon_id'], 'deleted' => (bool)$result, 'force' => $force];
} }
@@ -204,7 +204,7 @@ class WooTools {
public static function emptyCouponTrash(array $args): array { public static function emptyCouponTrash(array $args): array {
global $wpdb; global $wpdb;
$ids = $wpdb->get_col("SELECT ID FROM {$wpdb->posts} WHERE post_type='shop_coupon' AND post_status='trash'"); $ids = $wpdb->get_col("SELECT ID FROM {$wpdb->posts} WHERE post_type='shop_coupon' AND post_status='trash'");
$deleted = 0; $deleted = 0;
foreach ($ids as $id) { foreach ($ids as $id) {
if (wp_delete_post((int)$id, true)) $deleted++; if (wp_delete_post((int)$id, true)) $deleted++;
@@ -229,7 +229,7 @@ class WooTools {
if (empty($args['name'])) return ['error' => 'name is required']; if (empty($args['name'])) return ['error' => 'name is required'];
$slug = $args['slug'] ?? sanitize_title($args['name']); $slug = $args['slug'] ?? sanitize_title($args['name']);
$data = ['attribute_label' => $args['name'], 'attribute_name' => $slug, 'attribute_type' => $args['type'] ?? 'select', 'attribute_orderby' => $args['order_by'] ?? 'menu_order', 'attribute_public' => (int)($args['is_visible'] ?? 1)]; $data = ['attribute_label' => $args['name'], 'attribute_name' => $slug, 'attribute_type' => $args['type'] ?? 'select', 'attribute_orderby' => $args['order_by'] ?? 'menu_order', 'attribute_public' => (int)($args['is_visible'] ?? 1)];
$id = wc_create_attribute($data); $id = wc_create_attribute($data);
if (is_wp_error($id)) return ['error' => $id->get_error_message()]; if (is_wp_error($id)) return ['error' => $id->get_error_message()];
return ['id' => $id, 'slug' => 'pa_' . $slug, 'name' => $args['name'], 'created' => true]; return ['id' => $id, 'slug' => 'pa_' . $slug, 'name' => $args['name'], 'created' => true];
} }
@@ -340,8 +340,7 @@ class WooTools {
$results = ['created' => [], 'updated' => [], 'deleted' => []]; $results = ['created' => [], 'updated' => [], 'deleted' => []];
foreach ((array)($args['create'] ?? []) as $data) { foreach ((array)($args['create'] ?? []) as $data) {
$data['product_id'] = $args['product_id']; $data['product_id'] = $args['product_id'];
$r = self::createVariation($data); $results['created'][] = self::createVariation($data);
$results['created'][] = $r;
} }
foreach ((array)($args['update'] ?? []) as $data) { foreach ((array)($args['update'] ?? []) as $data) {
$results['updated'][] = self::updateVariation($data); $results['updated'][] = self::updateVariation($data);