PluginUs.Net - Business Tools for WooCommerce and WordPress

[realize your idea - make your dreams come true]

Support Forum

You need to log-in to create request (topic) to the support

Add custom field to "search by text"

The support doesn work on Saturdays and Sundays, so some Friday requests can be answered on Monday. If you have problems with registration ask help on contact us page please
If you not got email within 24~36 business hours, firstly check your spam box, and if no any email from the support there - back to the forum and read answer here. DO NOT ANSWER ON EMAILS [noreply@pluginus.net] FROM THE FORUM!! Emails are just for your info, all answers should be published only here.
The support doesn work on Saturdays and Sundays, so some Friday requests can be answered on Monday.

Hello,

I've created a custom field on my product page and I would like to ask you whether it is possible to add this custom field into Woof - search by text option?

Custom field code:

<?php

function mytheme_add_woocommerce_support() {
add_theme_support( 'woocommerce' );
}
add_action( 'after_setup_theme', 'mytheme_add_woocommerce_support' );

add_action( 'woocommerce_product_options_general_product_data', 'my_custom_field' );

function my_custom_field() {

woocommerce_wp_text_input(
array(
'id' => '_subtitle',
'label' => __( 'Subtitle', 'woocommerce' ),
'placeholder' => 'Subtitle....',
'description' => __( 'Enter the subtitle.', '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 ) );
}

 

Thank you

Hello

Please read this - https://products-filter.com/extencion/woocommerce-filter-by-meta-fields

Hi,

thanks for the quick response. As I understand this creates a separate filter. But is there a way to look through the custom field using the built-in"Search by text" option? Like this:
Search by title OR content OR excerpt OR"Custom field"

Thank you,

Jan

Hello Jan

in this case you need customization of the code

Use this  hook - https://products-filter.com/hook/woof_get_meta_query

To  get  current  text request:

global $WOOF;

$request = $WOOF->get_request_data();

$text_query = $request['woof_text'];