Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/256.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/wordpress/12.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php 自定义电子商务管理端添加项目模式_Php_Wordpress_Woocommerce - Fatal编程技术网

Php 自定义电子商务管理端添加项目模式

Php 自定义电子商务管理端添加项目模式,php,wordpress,woocommerce,Php,Wordpress,Woocommerce,大家好我希望你们能帮我, 问题是,我需要一个更好的产品查找在新的订单添加在管理方面的项目。由于我没有找到任何插件,我想我可以制作一个带有过滤器的模式来代替实际的模式。 现在的问题是,我在哪里可以找到要修改的代码,最好的方法是什么,有没有我没有见过的插件? 我很复杂,对不起,图片是西班牙文的 谢谢c:如果这与“添加新订单”页面中的“添加产品”相同,则过滤器“woocommerce\u json\u search\u found\u Products”将满足您的要求 # modified from

大家好我希望你们能帮我, 问题是,我需要一个更好的产品查找在新的订单添加在管理方面的项目。由于我没有找到任何插件,我想我可以制作一个带有过滤器的模式来代替实际的模式。 现在的问题是,我在哪里可以找到要修改的代码,最好的方法是什么,有没有我没有见过的插件? 我很复杂,对不起,图片是西班牙文的


谢谢c:

如果这与“添加新订单”页面中的“添加产品”相同,则过滤器“woocommerce\u json\u search\u found\u 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;
 });       

如果这与“添加新订单”页面的“添加产品”相同,则过滤器“woocommerce\u json\u search\u found\u 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;
 });       

如果这个提示还不够,请告诉我。我使用这个过滤器并且非常了解它。我发现了这个
//定义woocommerce\u json\u search\u found\u products回调函数filter\u woocommerce\u json\u search\u found\u products($products){//在这里实现过滤器的魔力…返回$products;};//添加过滤器添加过滤器('woocommerce\u json\u search\u found\u products','filter\u woocommerce\u json\u search\u found\u products',10,1)我想按标签过滤,有什么想法吗?>。过滤器位于产品描述数组上。但是,此数组的索引是产品id。因此,您可以使用产品id获取产品的任何属性。如果要从阵列中删除产品,可以使用array_filter()。如果这还不够清楚,请告诉我。我理解这一点,但查找器实际上是按产品名称过滤的,我的意思是,当我写下例如:Nike air model xyz 22时,它只在产品列表中搜索该名称。我需要列表来显示所有带有“nike”“shoes”“22”标签的产品,您知道我该如何做到这一点吗?:)实际上我刚刚发布了一个解决方案。如果这个提示还不够,请告诉我。我使用这个过滤器并且非常了解它。我发现了这个
//定义woocommerce\u json\u search\u found\u products回调函数filter\u woocommerce\u json\u search\u found\u products($products){//在这里实现过滤器的魔力…返回$products;};//添加过滤器添加过滤器('woocommerce\u json\u search\u found\u products','filter\u woocommerce\u json\u search\u found\u products',10,1)我想按标签过滤,有什么想法吗?>。过滤器位于产品描述数组上。但是,此数组的索引是产品id。因此,您可以使用产品id获取产品的任何属性。如果要从阵列中删除产品,可以使用array_filter()。如果这还不够清楚,请告诉我。我理解这一点,但查找器实际上是按产品名称过滤的,我的意思是,当我写下例如:Nike air model xyz 22时,它只在产品列表中搜索该名称。我需要列表来显示所有带有“nike”“shoes”“22”标签的产品,您知道我该如何做到这一点吗?:)实际上我刚刚发布了一个解决方案。