Example #1
0
/**
 * Get a ShoppProductTaxonomy object.
 *
 * @api
 * @since 1.2
 *
 * @param int $term the term id
 * @param string $taxonomy (optional default:shopp_category) the taxonomy name
 * @param array $options (optional) loading options
 * @return bool|ProductTaxonomy returns false on error, ProductTaxonomy object on success
 **/
function shopp_product_term($term = false, $taxonomy = 'shopp_category', $options = array())
{
    global $ShoppTaxonomies;
    if (!$term) {
        shopp_debug(__FUNCTION__ . " failed: Term id required.");
        return false;
    }
    if (in_array($taxonomy, array_keys($ShoppTaxonomies))) {
        // Shopp ProductTaxonomy class type
        $Term = new $ShoppTaxonomies[$taxonomy]($term);
    } else {
        $term = term_exists($term, $taxonomy);
        if (!is_array($term)) {
            return false;
        }
        $Term = new ProductTaxonomy();
        $Term->taxonomy = $taxonomy;
        $Term->load_term($term['term_id']);
    }
    if (!$Term->id) {
        return false;
    }
    $Term->load($options);
    return $Term;
}