Is it possible to use a WooCommerce shortcode e.g. [product_category category=\"appliances\"]
amending the markup to include a
@Updated
Yes this is absolutely possible. You can achieve this with something like that:
if( !function_exists('prod_cat') ) {
function prod_cat( $atts ) {
extract(shortcode_atts(array(
'cat' => '', // category
'class' => '' // Optional adding class to tag
), $atts));
if ( $class != '') {
$class = ' class="' . $class . '"';
}
return '' . do_shortcode("[product_category category=" . $cat . "]") . '';
}
add_shortcode('prod_cat', 'prod_cat');
}
Paste the above code snippet in the function.php file of active child theme or theme
This code is tested and fully functional.
USAGE:
You have 2 arguments for this the shortcode
:
cat="your_category"
to set your category
class="your_div_class"
to set css classes to the tag (optional).
You can use it in any woocommerce page as any shortcode does:
[prod_cat cat="appliances" class="my_optional_div_class"]
讨论(0)