Php 扩展WooCommerce产品过滤器插件shortocodes
我正在使用Woocommerce和WOOF插件(Woocommerce过滤器)。特别是,该插件可以显示一个过滤器,该过滤器将仅使用例如Php 扩展WooCommerce产品过滤器插件shortocodes,php,wordpress,woocommerce,plugins,shortcode,Php,Wordpress,Woocommerce,Plugins,Shortcode,我正在使用Woocommerce和WOOF插件(Woocommerce过滤器)。特别是,该插件可以显示一个过滤器,该过滤器将仅使用例如[woof taxonomies=product\u cat:23]快捷码搜索特定的产品类别,并使用[woof\u products taxonomies=product\u cat:23]快捷码显示结果,其中23是商品的类别id 但是,并非总是可以在短代码本身中指定类别,我希望实现允许您使用类似于[woof taxonomics=product\u cat:au
[woof taxonomies=product\u cat:23]
快捷码搜索特定的产品类别,并使用[woof\u products taxonomies=product\u cat:23]
快捷码显示结果,其中23
是商品的类别id
但是,并非总是可以在短代码本身中指定类别,我希望实现允许您使用类似于[woof taxonomics=product\u cat:auto]
的短代码的功能,它将使用特定函数自动确定当前类别,例如,此(功能已测试并正常工作):
当然,我可以为这个函数创建一个短代码,并将其添加到主题的functions.php
:
add_shortcode('show_product_category_id','show_product_category_id');
它会起作用的。但我不能使用这样的结构:
[woof分类法=产品类别:[显示产品类别id]]
因为Wordpress中的嵌套短代码不起作用。因此,显然,我需要向woocommerce添加不仅指定product_cat:35,还指定product_cat:auto的功能
我怎样才能实现它?或者,在wordpress中也有使用嵌套短代码的方法吗?当然,不能将短代码嵌套在另一个短代码中,但可以将短代码嵌入到另一个短代码中,如下所示:
function woof_current_product_category_id() {
$term = get_queried_object();
$term_id = 0; // Initializing
if ( isset($_GET['really_curr_tax']) && false !== strpos( $_GET['really_curr_tax'], 'product_cat' ) ) {
$term_id = (int) str_replace('-product_cat', '', $_GET['really_curr_tax']);
} elseif ( is_a($term, 'WP_Term') ) {
$term_id = (int) $term->term_id;
}
return do_shortcode("[woof taxonomies=product_cat:$term_id]"); // Always use return for a shortcode
}
add_shortcode( 'show_product_category_id', 'woof_current_product_category_id' );
代码进入活动子主题(或活动主题)的functions.php文件
因此,它的用法就是:
[show\u product\u category\u id]
这是我需要的,当然。我还为结果制作了[show\u result\u product\u category\u id]快捷码(而不是[woof\u products])。感谢您的解决方案
function woof_current_product_category_id() {
$term = get_queried_object();
$term_id = 0; // Initializing
if ( isset($_GET['really_curr_tax']) && false !== strpos( $_GET['really_curr_tax'], 'product_cat' ) ) {
$term_id = (int) str_replace('-product_cat', '', $_GET['really_curr_tax']);
} elseif ( is_a($term, 'WP_Term') ) {
$term_id = (int) $term->term_id;
}
return do_shortcode("[woof taxonomies=product_cat:$term_id]"); // Always use return for a shortcode
}
add_shortcode( 'show_product_category_id', 'woof_current_product_category_id' );