Your question should be specific to WordPress. Generic PHP/JS/SQL/HTML/CSS questions might be better asked at Stack Overflow or another appropriate Stack Exchange network site. Third-party plugins and themes are off-topic for this site; they are better asked about at their developers' support routes.
Closed 5 years ago.
Improve this questionI am trying to concatenate my post meta data to my search results title using the Advanced Woo Search plugin. The documentation give the following filter but I am unsure as to what to enter as the parameters:
Here is the code I have so far to access the post meta data and store it in the variables. All I need help with is hooking it with the above filter to make my search results title different.
// Display Fields
add_action('woocommerce_product_options_general_product_data', 'woocommerce_product_custom_fields');
// Save Fields
add_action('woocommerce_process_product_meta', 'woocommerce_product_custom_fields_save');
function woocommerce_product_custom_fields() {
global $woocommerce, $post;
echo '<div class="product_custom_field">';
// Custom Product Text Field 1
woocommerce_wp_text_input(
array(
'id' => '_tyre_size_field',
'placeholder' => 'Tyre Size',
'label' => __('Tyre Size', 'woocommerce'),
'desc_tip' => 'true'
)
);
// Custom Product Text Field 2
woocommerce_wp_text_input(
array(
'id' => '_load_speed_field',
'placeholder' => 'Load Index & Speed Rating',
'label' => __('Load Index & Speed Rating', 'woocommerce'),
'desc_tip' => 'true'
)
);
// Custom Product Text Field 3
woocommerce_wp_text_input(
array(
'id' => '_tyre_brand_field',
'placeholder' => 'Tyre Brand',
'label' => __('Tyre Brand', 'woocommerce'),
'desc_tip' => 'true'
)
);
// Custom Product Text Field 4
woocommerce_wp_text_input(
array(
'id' => '_brand_model_field',
'placeholder' => 'Brand Model',
'label' => __('Brand Model', 'woocommerce'),
'desc_tip' => 'true'
)
);
// Custom Product Text Field 5
woocommerce_wp_select( array(
'id' => '_run_flat_field',
'label' => __( 'Run Flat or Non-Run Flat', 'woocommerce' ),
'description' => __( 'Choose whether the tyre is run-flat or non-run flat.', 'woocommerce' ),
'desc_tip' => true,
'options' => array(
' ' => __( ' ', 'woocommerce' ),
'RUN FLAT' => __('RUN FLAT', 'woocommerce' ),
'NON-RUN FLAT' => __('NON-RUN FLAT', 'woocommerce' ),
)
) );
echo '</div>';
}
function woocommerce_product_custom_fields_save($post_id) {
// Custom Product Text Field 1
$woocommerce_custom_product_tyre_size_field = $_POST['_tyre_size_field'];
if (!empty($woocommerce_custom_product_tyre_size_field))
update_post_meta($post_id, '_tyre_size_field', esc_attr($woocommerce_custom_product_tyre_size_field));
// Custom Product Text Field 2
$woocommerce_custom_product_tyre_brand_field = $_POST['_tyre_brand_field'];
if (!empty($woocommerce_custom_product_tyre_brand_field))
update_post_meta($post_id, '_tyre_brand_field', esc_attr($woocommerce_custom_product_tyre_brand_field));
// Custom Product Text Field 3
$woocommerce_custom_product_brand_model_field = $_POST['_brand_model_field'];
if (!empty($woocommerce_custom_product_brand_model_field))
update_post_meta($post_id, '_brand_model_field', esc_attr($woocommerce_custom_product_brand_model_field));
// Custom Product Text Field 4
$woocommerce_custom_product_run_flat_field = $_POST['_run_flat_field'];
if (!empty($woocommerce_custom_product_run_flat_field))
update_post_meta($post_id, '_run_flat_field', esc_attr($woocommerce_custom_product_run_flat_field));
// Custom Product Text Field 5
$woocommerce_custom_product_load_speed_field = $_POST['_load_speed_field'];
if (!empty($woocommerce_custom_product_load_speed_field))
update_post_meta($post_id, '_load_speed_field', esc_attr($woocommerce_custom_product_load_speed_field));
}
function concatenate_fields_to_title( $title ) {
global $post;
$text1 = get_post_meta( $post->ID, '_tyre_size_field', true );
$text2 = get_post_meta( $post->ID, '_load_speed_field', true );
$text3 = get_post_meta( $post->ID, '_tyre_brand_field', true );
$text4 = get_post_meta( $post->ID, '_brand_model_field', true );
$text5 = get_post_meta( $post->ID, '_run_flat_field', true );
if (stripos( $title, 'TYRE' ) == true ) {
return $text1 . " ". $text2 . " " . $text3 . " " . $text4 . " " . $text5 . " " . $title;
}
return $title;
}
add_filter( 'the_title', 'concatenate_fields_to_title' );
Closed. This question is off-topic. It is not currently accepting answers.
Your question should be specific to WordPress. Generic PHP/JS/SQL/HTML/CSS questions might be better asked at Stack Overflow or another appropriate Stack Exchange network site. Third-party plugins and themes are off-topic for this site; they are better asked about at their developers' support routes.
Closed 5 years ago.
Improve this questionI am trying to concatenate my post meta data to my search results title using the Advanced Woo Search plugin. The documentation give the following filter but I am unsure as to what to enter as the parameters:
Here is the code I have so far to access the post meta data and store it in the variables. All I need help with is hooking it with the above filter to make my search results title different.
// Display Fields
add_action('woocommerce_product_options_general_product_data', 'woocommerce_product_custom_fields');
// Save Fields
add_action('woocommerce_process_product_meta', 'woocommerce_product_custom_fields_save');
function woocommerce_product_custom_fields() {
global $woocommerce, $post;
echo '<div class="product_custom_field">';
// Custom Product Text Field 1
woocommerce_wp_text_input(
array(
'id' => '_tyre_size_field',
'placeholder' => 'Tyre Size',
'label' => __('Tyre Size', 'woocommerce'),
'desc_tip' => 'true'
)
);
// Custom Product Text Field 2
woocommerce_wp_text_input(
array(
'id' => '_load_speed_field',
'placeholder' => 'Load Index & Speed Rating',
'label' => __('Load Index & Speed Rating', 'woocommerce'),
'desc_tip' => 'true'
)
);
// Custom Product Text Field 3
woocommerce_wp_text_input(
array(
'id' => '_tyre_brand_field',
'placeholder' => 'Tyre Brand',
'label' => __('Tyre Brand', 'woocommerce'),
'desc_tip' => 'true'
)
);
// Custom Product Text Field 4
woocommerce_wp_text_input(
array(
'id' => '_brand_model_field',
'placeholder' => 'Brand Model',
'label' => __('Brand Model', 'woocommerce'),
'desc_tip' => 'true'
)
);
// Custom Product Text Field 5
woocommerce_wp_select( array(
'id' => '_run_flat_field',
'label' => __( 'Run Flat or Non-Run Flat', 'woocommerce' ),
'description' => __( 'Choose whether the tyre is run-flat or non-run flat.', 'woocommerce' ),
'desc_tip' => true,
'options' => array(
' ' => __( ' ', 'woocommerce' ),
'RUN FLAT' => __('RUN FLAT', 'woocommerce' ),
'NON-RUN FLAT' => __('NON-RUN FLAT', 'woocommerce' ),
)
) );
echo '</div>';
}
function woocommerce_product_custom_fields_save($post_id) {
// Custom Product Text Field 1
$woocommerce_custom_product_tyre_size_field = $_POST['_tyre_size_field'];
if (!empty($woocommerce_custom_product_tyre_size_field))
update_post_meta($post_id, '_tyre_size_field', esc_attr($woocommerce_custom_product_tyre_size_field));
// Custom Product Text Field 2
$woocommerce_custom_product_tyre_brand_field = $_POST['_tyre_brand_field'];
if (!empty($woocommerce_custom_product_tyre_brand_field))
update_post_meta($post_id, '_tyre_brand_field', esc_attr($woocommerce_custom_product_tyre_brand_field));
// Custom Product Text Field 3
$woocommerce_custom_product_brand_model_field = $_POST['_brand_model_field'];
if (!empty($woocommerce_custom_product_brand_model_field))
update_post_meta($post_id, '_brand_model_field', esc_attr($woocommerce_custom_product_brand_model_field));
// Custom Product Text Field 4
$woocommerce_custom_product_run_flat_field = $_POST['_run_flat_field'];
if (!empty($woocommerce_custom_product_run_flat_field))
update_post_meta($post_id, '_run_flat_field', esc_attr($woocommerce_custom_product_run_flat_field));
// Custom Product Text Field 5
$woocommerce_custom_product_load_speed_field = $_POST['_load_speed_field'];
if (!empty($woocommerce_custom_product_load_speed_field))
update_post_meta($post_id, '_load_speed_field', esc_attr($woocommerce_custom_product_load_speed_field));
}
function concatenate_fields_to_title( $title ) {
global $post;
$text1 = get_post_meta( $post->ID, '_tyre_size_field', true );
$text2 = get_post_meta( $post->ID, '_load_speed_field', true );
$text3 = get_post_meta( $post->ID, '_tyre_brand_field', true );
$text4 = get_post_meta( $post->ID, '_brand_model_field', true );
$text5 = get_post_meta( $post->ID, '_run_flat_field', true );
if (stripos( $title, 'TYRE' ) == true ) {
return $text1 . " ". $text2 . " " . $text3 . " " . $text4 . " " . $text5 . " " . $title;
}
return $title;
}
add_filter( 'the_title', 'concatenate_fields_to_title' );
Share
Improve this question
asked Jul 3, 2019 at 13:40
NDT-AMNDT-AM
34 bronze badges
1 Answer
Reset to default 1Please try to use following code
add_filter( 'aws_title_search_result', 'my_aws_title_search_result', 10, 3 );
function my_aws_title_search_result( $title, $post_id, $product ) {
$text1 = get_post_meta( $post_id, '_tyre_size_field', true );
$text2 = get_post_meta( $post_id, '_load_speed_field', true );
$text3 = get_post_meta( $post_id, '_tyre_brand_field', true );
$text4 = get_post_meta( $post_id, '_brand_model_field', true );
$text5 = get_post_meta( $post_id, '_run_flat_field', true );
if (stripos( $title, 'TYRE' ) == true ) {
$title = $text1 . " ". $text2 . " " . $text3 . " " . $text4 . " " . $text5 . " " . $title;
}
return $title;
}
Also after this you will probably need to go to plugin settings page and click 'Clear cache' button.