Closed. This question is off-topic. It is not currently accepting answers.admin管理员组文章数量:1421700
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.
本文标签: pluginsHow can I concatenate variables to search results title
版权声明:本文标题:plugins - How can I concatenate variables to search results title? 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1745347132a2654540.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论