php facetwp woocommerce _product_attributes

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了php facetwp woocommerce _product_attributes相关的知识,希望对你有一定的参考价值。

<?php
/** some types of product attributes for woocommerce (those that are not taxonomies or used for variations
 ** are saved only in the _product_attributes custom field as an array
 ** select "_product_attributes" as the datasource in the facet and use facetwp_index_row to find and index
 ** the correct attributes
 **/

add_filter( 'facetwp_index_row', function( $params, $class ) {
    if ( 'attributes' == $params['facet_name'] ) { //change 'attributes' to name of your facet
        $values = maybe_unserialize( $params['facet_value'] );
        if ( is_array( $values ) && ! empty( $values ) ) {
            foreach ( $values as $key => $value ) {
                if ( 'test-attr' == $key ) { // Name of attribute, lowercase, "-" in place of spaces, "Test Attr" = 'test-attr'	
                    $attrs = explode( '|', $value['value'] );
                    foreach ( $attrs as $attr ) {
                        $params['facet_value'] = trim( $attr );
                        $params['facet_display_value'] = $params['facet_value'];
                        $class->insert( $params ); // insert new value to the database
                    }
                }
            }
        }
        $params['facet_value'] = ''; // skip original row
    }
    return $params;
}, 10, 2 );

以上是关于php facetwp woocommerce _product_attributes的主要内容,如果未能解决你的问题,请参考以下文章

php facetwp在facetwp模板中使用woocommerce占位符图像

php facetwp woocommerce facetwp-template with hooks

php facetwp指数“任何”的woocommerce变化

php facetwp woocommerce术语描述

php facetwp输出woocommerce明星

php facetwp woocommerce布局构建器