How To Add Multiple Product Categories To WP eCommerce Plugin

Total
0
Shares
e Commerce

WP e-Commerce is a free WordPress Shopping Cart Plugin that lets customers buy your products, services and digital downloads online. WP Shopping Cart Plugin is a paid plugin, it seems to be of better quality than the free versions as well as slightly easier to use. It has more features as compare to the free one. Even there are WordPress Themes with eCommerce features, you can find the theme on the following links:

If you are using this plugin as an e-Commerce platform and want to add multiple categories, here give you a solution for that and by using this code you can create your own Plugin to add bulk Product categories for your online shop. You can read all about WP-eCommerce Plugin here: Create Online Store with Free WordPress e-Commerce plugin

<?php
/*
Plugin Name: Add Product Categories
Version: v0.1
Author: WordPress Arena
URL: https://wparena.com
Description: Bulk category import for WP-eCommerce Plugin
Plugin URI: https://wparena.com/?p=10921
Author URI: https://wparena.com
*/
function batch_import_function() {
global $wpdb;
if(isset($_POST['Add'])) {

$group_id = $_POST['groupid'];
$parent_id = $_POST['category'];
$categories = $_POST['categories'];
$cats_array = explode(",",$categories);
print_r ($cats_array);
foreach($cats_array as $key => $value) {
$nice_name = str_replace (" ","-",$value);
echo ($nice_name);
$wpdb->insert(
	'wp_wpsc_product_categories',
	array(
		'group_id' => $group_id,
		'name' => $value,
		'nice-name' => $nice_name,
		'active' => 1,
		'category_parent' => $parent_id
		),
	array(
		'%s',
		'%s',
		'%s',
		'%d',
		'%d'
	)
);
}
  }
?>
<form name="batchcats" action="" method="post">
Group:<input type="text" name="groupid" />
Parent Category:<input type="text" name="category" />
Categories:<textarea name="categories"></textarea>
<input name="Add" type="submit" value="Add" />
</form>
<?php
}
function batch_import() {
      add_menu_page("Import Categories", "Import Categories", 1, "Import Categories", "batch_import_function");
}
add_action('admin_menu', 'batch_import');
?>

Save this file as a .php and upload it into plugin directory, activate the plugin and you will see “Import Categories” tab in your admin panel. Click on this tab and add Group id number and add Parent Category id, after adding ids entry the categories name separated by commas and click on add button.

WordPress Themes for eCommerce

Leave a Reply

Your email address will not be published. Required fields are marked *

Sign Up for Our Newsletters

Get notified of the best deals on our WordPress themes.

You May Also Like