Skip to content

Instantly share code, notes, and snippets.

@not-only-code
Created December 7, 2012 12:59
Show Gist options
  • Save not-only-code/4233110 to your computer and use it in GitHub Desktop.
Save not-only-code/4233110 to your computer and use it in GitHub Desktop.
Theming Jigoshop: create your custom product types
/**
* Helper functions to add / remove array of terms
*
* @package MyTheme
* @since 1.0
*
**/
function _add_terms( $terms, $taxonomy = 'category' ) {
if ( !is_array($terms) || empty($terms)) return;
foreach($terms as $term)
if (!$term_ = get_term_by( 'slug', sanitize_title($term), 'product_type'))
wp_insert_term($term, $taxonomy);
}
function _remove_terms( $terms, $taxonomy = 'category' ) {
if ( !is_array($terms) || empty($terms)) return;
foreach($terms as $term)
if ($term_ = get_term_by( 'slug', sanitize_title($term), 'product_type'))
wp_delete_term( $term_->term_id, $taxonomy);
}
/**
* Remove 'product types' doesn't needed for the site
*
* @package MyTheme
* @since 1.0
*
**/
function mytheme_remove_product_types() {
if ( get_option('mytheme_jigoshop_adapted') != 'yes' ):
$remove_types = array( 'External', 'Grouped', 'Configurable', 'Downloadable', 'Virtual' );
$add_types = array( 'Custom' );
_remove_terms($remove_types, 'product_type');
_add_terms($add_types, 'product_type');
update_option('mytheme_jigoshop_adapted', 'yes');
endif;
}
include_once( ABSPATH . 'wp-admin/includes/plugin.php' );
if (is_plugin_active('jigoshop/jigoshop.php'))
add_action( 'init', 'mytheme_remove_product_types', 640 );
/**
* Product type selector
*
* @package MyTheme
* @since 1.0
*
**/
function mytheme_product_type_selector($product_types) {
return array(
'simple' => __('Simple', 'jigoshop'),
'custom' => __('Custom', 'mytheme');
);
}
add_filter('jigoshop_product_type_selector', 'mytheme_product_type_selector', 0);
/**
* Adds product types doesn't needed for the site
*
* @package MyTheme
* @since 1.0
*
**/
function mytheme_add_product_types() {
$add_types = array( 'External', 'Grouped', 'Configurable', 'Downloadable', 'Virtual' );
$remove_types = array( 'Custom' );
_add_terms($add_types, 'product_type');
_remove_terms($remove_types, 'product_type');
delete_option('mytheme_jigoshop_adapted');
}
register_deactivation_hook( 'jigoshop/jigoshop.php', 'mytheme_add_product_types' );
add_action("switch_theme", "mytheme_add_product_types");
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment