目前,搜索结果仅显示所有woocommerce默认产品字段(产品标题、类别、标签等)。
我在woocommerce产品中添加了一个新的自定义字段,并在函数中使用了此代码。php
/** Add Sub-Title option in Woocommerce */
add_action( \'woocommerce_product_options_general_product_data\', \'my_custom_field\' );
function my_custom_field() {
woocommerce_wp_text_input(
array(
\'id\' => \'_subtitle\',
\'label\' => __( \'Reference\', \'woocommerce\' ),
\'placeholder\' => \'Reference code\',
\'description\' => __( \'Enter the reference code\', \'woocommerce\' )
)
);
}
add_action( \'woocommerce_process_product_meta\', \'my_custom_field_save\' );
function my_custom_field_save( $post_id ){
$subtitle = $_POST[\'_subtitle\'];
if( !empty( $subtitle ) )
update_post_meta( $post_id, \'_subtitle\', esc_attr( $subtitle ) );
}
How can I include this custom field value in the search result? 我尝试过谷歌,但没有任何有效的解决方案。