Change markup in WooCommerce shortcode output

后端 未结 1 887
青春惊慌失措
青春惊慌失措 2021-01-21 21:53

Is it possible to use a WooCommerce shortcode e.g. [product_category category=\"appliances\"] amending the markup to include a

1条回答
  •  野趣味
    野趣味 (楼主)
    2021-01-21 22:31

    @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 讨论(0)
提交回复
热议问题