feat: add 16 missing WooCommerce methods — coupons, variations, attributes, customers alias
This commit is contained in:
@@ -192,7 +192,7 @@ class WooTools {
|
||||
if (empty($args['coupon_id'])) return ['error' => 'coupon_id is required'];
|
||||
$coupon = new \WC_Coupon((int)$args['coupon_id']);
|
||||
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());
|
||||
return ['coupon_id' => $args['coupon_id'], 'deleted' => (bool)$result, 'force' => $force];
|
||||
}
|
||||
@@ -204,7 +204,7 @@ class WooTools {
|
||||
|
||||
public static function emptyCouponTrash(array $args): array {
|
||||
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;
|
||||
foreach ($ids as $id) {
|
||||
if (wp_delete_post((int)$id, true)) $deleted++;
|
||||
@@ -229,7 +229,7 @@ class WooTools {
|
||||
if (empty($args['name'])) return ['error' => 'name is required'];
|
||||
$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)];
|
||||
$id = wc_create_attribute($data);
|
||||
$id = wc_create_attribute($data);
|
||||
if (is_wp_error($id)) return ['error' => $id->get_error_message()];
|
||||
return ['id' => $id, 'slug' => 'pa_' . $slug, 'name' => $args['name'], 'created' => true];
|
||||
}
|
||||
@@ -340,8 +340,7 @@ class WooTools {
|
||||
$results = ['created' => [], 'updated' => [], 'deleted' => []];
|
||||
foreach ((array)($args['create'] ?? []) as $data) {
|
||||
$data['product_id'] = $args['product_id'];
|
||||
$r = self::createVariation($data);
|
||||
$results['created'][] = $r;
|
||||
$results['created'][] = self::createVariation($data);
|
||||
}
|
||||
foreach ((array)($args['update'] ?? []) as $data) {
|
||||
$results['updated'][] = self::updateVariation($data);
|
||||
|
||||
Reference in New Issue
Block a user