Plugin Directory

Changeset 3217706


Ignore:
Timestamp:
01/06/2025 12:51:32 PM (14 months ago)
Author:
spreadr
Message:

Product category creation fix

Location:
spreadr-for-woocomerce
Files:
9 added
3 edited

Legend:

Unmodified
Added
Removed
  • spreadr-for-woocomerce/trunk/includes/spreadr-core-functions.php

    r3206748 r3217706  
    139139        } elseif ($meta['key'] == 'spreadr_category') {
    140140           
    141             wp_set_object_terms($post_id, $meta['value'], 'product_cat');
     141            $category_name =  $meta['value'];
     142           
     143              // Check if the category exists by name
     144                $category = get_term_by( 'name', $category_name, 'product_cat' );
     145
     146                if ( ! $category ) {
     147                    // Create the category if it doesn't exist
     148                    $category_id = wp_insert_term( $category_name, 'product_cat' );
     149
     150                    // Handle potential errors during category creation
     151                    if ( is_wp_error( $category_id ) ) {
     152                        error_log( 'Error creating category: ' . $category_id->get_error_message() );
     153                        return;
     154                    }
     155
     156                    // Get the term_id of the newly created category
     157                    $category_id = $category_id['term_id'];
     158                } else {
     159                    // Use the existing category's term_id
     160                    $category_id = $category->term_id;
     161                }
     162
     163                // Assign the category to the product
     164                wp_set_object_terms( $post_id, (int) $category_id, 'product_cat', true );
    142165        }
    143166       
  • spreadr-for-woocomerce/trunk/readme.txt

    r3206748 r3217706  
    8787== Changelog ==
    8888
     89= 1.0.6 - January 6, 2025 =
     90* Fixed Category Issue.
     91
    8992= 1.0.5 - December 12, 2024 =
    9093* Security Fixes:
  • spreadr-for-woocomerce/trunk/spreadr.php

    r3206748 r3217706  
    55 * Plugin URI: https://spreadr.co/woocommerce
    66 * Description: Use Spreadr Plugin to import products from Amazon to your WooCommerce store. Earn commissions via Amazon Affiliate Program or run your dropshipping business.
    7  * Version: 1.0.5
     7 * Version: 1.0.6
    88 * Author: spreadr
    99 * Author URI: https://spreadr.co
Note: See TracChangeset for help on using the changeset viewer.