2017-06-30 44 views
0

你好家伙,我希望你能帮助我, 问题是,我需要一个更好的产品查找器在新订单管理端添加项目。因为我没有找到任何插件,我认为我可以使用可以替换实际的滤镜的一种模式。 现在的问题是,我在哪里可以找到要修改的代码,最好的方法是做什么,有没有我没见过的插件? 我非常复杂,遗憾的图像在西班牙自定义Woocommerce管理端添加项目模式

enter image description here

感谢C:

回答

1

如果这是一样的“添加新秩序”页面的“添加产品”,那么过滤'woocommerce_json_search_found_products'会做你想做的。

# modified from WC_AJAX::json_search_products() 
# untested but should point you in the right direction 

add_filter('woocommerce_json_search_found_products', function($products) { 
    $term = wc_clean(stripslashes($_GET['term'])); 
    # split the term into terms 
    $terms = explode(' ', $term); 

    $data_store = WC_Data_Store::load('product'); 
    $ids = []; 
    foreach ($terms as $term) { 
     # do a search for each term and join the result 
     $ids = array_merge($ids, $data_store->search_products($term, '', false)); 
    } 
    $ids = array_unique($ids); 

    if (! empty($_GET['exclude'])) { 
     $ids = array_diff($ids, (array) $_GET['exclude']); 
    } 

    if (! empty($_GET['include'])) { 
     $ids = array_intersect($ids, (array) $_GET['include']); 
    } 

    if (! empty($_GET['limit'])) { 
     $ids = array_slice($ids, 0, absint($_GET['limit'])); 
    } 

    $product_objects = array_filter(array_map('wc_get_product', $ids), 'wc_products_array_filter_editable'); 
    $products  = array(); 

    foreach ($product_objects as $product_object) { 
     $products[ $product_object->get_id() ] = rawurldecode($product_object->get_formatted_name()); 
    } 

    return $products; 
});  
+0

让我知道,如果这个提示是不够的。我使用这个过滤器并且非常了解它。 –

+0

我发现这个'// define the woocommerce_json_search_found_products callback function filter_woocommerce_json_search_found_products($ products){ //使得过滤魔术在这里发生... return $ products; }; //添加过滤器 add_filter('woocommerce_json_search_found_products','filter_woocommerce_json_search_found_products',10,1);'我想过滤标签,任何想法? >。< –

+0

该过滤器位于产品说明数组中。但是,此数组的索引是产品ID。因此,您可以使用产品ID来获取产品的任何属性。如果你想从数组中删除产品,你可以使用array_filter()。让我知道如果这不够清楚。 –

相关问题