Well, i disabled the woocommerce option in the features page of the plugin and the sorting option is working correctly now. My other issue now is that when im searching an SKU i get some products as an result but not the one with the sku that i searched.
I was also tried to insert the _sku field in the mapping but with no luck. Do you have any suggestion, why the search by sku is not wokring?
The other field “brand code” that i added is working fine. I created the field brand code with ACF.
function custom_ep_config_mapping( $mapping ) {
$mapping['mappings']['properties']['menu_order'] = [
'type' => 'integer',
];
$mapping['mappings']['properties']['total_sales'] = [
'type' => 'integer',
];
$mapping['mappings']['properties']['brand_code'] = [
'type' => 'keyword',
];
$mapping['mappings']['properties']['hidden_tags'] = [
'type' => 'text',
'analyzer' => 'standard',
];
$mapping['mappings']['properties']['_sku'] = [
'type' => 'text',
'analyzer' => 'keyword',
];
return $mapping;
}
add_filter( 'ep_config_mapping', 'custom_ep_config_mapping' );
// Add sku and brand code in the elastic search
function OM_ep_weighting( $fields, $post_type ) {
if ( 'product' === $post_type ) {
if ( empty( $fields['meta'] ) ) {
$fields['meta'] = array(
'label' => 'Custom Fields',
'children' => array(),
);
}
// Add 'sku' field
$sku_key = 'meta._sku.value';
$fields['meta']['children'][ $sku_key ] = array(
'key' => $sku_key,
'label' => __( 'SKU', 'textdomain' ),
'exact' => true,
// 'weight' => 10,
);
// Add 'brand_code' field
$brand_code_key = 'meta.brand_code.value';
$fields['meta']['children'][ $brand_code_key ] = array(
'key' => $brand_code_key,
'label' => __( 'Brand Code', 'textdomain' ),
'exact' => true,
// 'weight' => 50,
);
}
return $fields;
}
add_filter('ep_weighting_fields_for_post_type','OM_ep_weighting',10,2);