前言
使用此筛选器可自定义 WooCommerce 元素的设置与渲染逻辑。
用法
将代码加入子主题的 functions.php:
// Output one or more instances of the specified element (inside a query loop of ACF Repeater type) when the condition is true.
// Condition: The specified sub field inside the specified ACF Repeater field is not empty.
add_filter( 'bricks/element/render', function( $render, $element ) {
if ( $element->id === 'huciku' && class_exists( 'ACF' ) ) {
if ( have_rows( 'faqs' ) ) {
// Loop through rows.
while( have_rows( 'faqs' ) ) : the_row();
return get_sub_field( 'button_text' );
// End loop.
endwhile;
}
}
return $render;
}, 10, 2 );
示例代码
筛选返回值
// Output one or more instances of the specified element (inside a query loop of ACF Repeater type) when the condition is true.
// Condition: The specified sub field inside the specified ACF Repeater field is not empty.
add_filter( 'bricks/element/render', function( $render, $element ) {
if ( $element->id === 'huciku' && class_exists( 'ACF' ) ) {
if ( have_rows( 'faqs' ) ) {
// Loop through rows.
while( have_rows( 'faqs' ) ) : the_row();
return get_sub_field( 'button_text' );
// End loop.
endwhile;
}
}
return $render;
}, 10, 2 );
补充说明
更多细节可参考 官方文档。