Change markup in WooCommerce shortcode output

痞子三分冷 提交于 2019-12-02 01:16:06

@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 <div> tag


        ), $atts));

        if ( $class != '') {
            $class = ' class="' . $class . '"';
        }

        return '<div'.$class.'>' . do_shortcode("[product_category category=" . $cat . "]") . '</div>';

    }

    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 <div> tag (optional).

You can use it in any woocommerce page as any shortcode does:

[prod_cat cat="appliances" class="my_optional_div_class"]
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!