php facetwp指数“任何”的woocommerce变化
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了php facetwp指数“任何”的woocommerce变化相关的知识,希望对你有一定的参考价值。
<?php
/** handles indexing when a woocommerce variation has "any" selected instead of specific values **/
add_filter( 'facetwp_indexer_row_data', function( $rows, $args ) {
if ( 0 === strpos( $args['defaults']['facet_source'], 'cf/attribute_pa_' ) ) {
foreach ( $rows AS $row ) {
if ( 'product_variation' == get_post_type( $row['post_id'] ) && '' == $row['facet_value'] ) {
$parent = wp_get_post_parent_id( $row['post_id'] );
if ( 0 === strpos( $row['facet_source'], 'cf/attribute_pa_' ) ) {
$taxonomy = str_replace( 'cf/attribute_', '', $row['facet_source'] );
$terms = get_the_terms( $parent, $taxonomy );
if ( !is_wp_error( $terms ) && !empty( $terms ) ) {
foreach ( $terms AS $term ) {
$params = $row;
$params['term_id'] = $term->term_id;
$params['facet_display_value'] = $term->name;
$params['facet_value'] = $term->slug;
$params['variation_id'] = $row['post_id'];
$params['post_id'] = $parent;
$rows[] = $params;
}
}
}
}
}
}
return $rows;
}, 11,2 );
以上是关于php facetwp指数“任何”的woocommerce变化的主要内容,如果未能解决你的问题,请参考以下文章
php facetwp检查是否选择了任何方面
php facetwp facetwp-woocommerce的模板
php facetwp用facetwp替换genesis pager
php facetwp仅启用了facetwp的bb模块的主查询
php facetwp在GeneratePress中显示facetwp寻呼机
php facetwp添加facetwp-template下载短代码