1

我想允许我的 Dokan 市场上的用户按位置过滤供应商。我在我的 functions.php 文件中编写了以下代码:

/**
 *  list of vendors by location 
 * 
 *  @param $atts shortcode attributs 
 */
function dokan_vendors_location( $atts ) {
    $html = ''; 

    extract( shortcode_atts( array(
        'orderby'       => 'display_name',
        'order'         => 'ASC',
        'per_page'      => '12',
        'columns'       => '4', 
        'show_products' => 'yes',
        'location'      => '',
        'org'           => '',
    ), $atts ) );

    // Hook into the user query to modify the query to return users that have at least one product 
    if ($show_products == 'yes') remove_action( 'pre_user_query', array( $this, 'vendors_with_products') );

    // Get all vendors 
    $vendor_total_args = array ( 
        'role'              => 'vendor', 
        'meta_key'          => 'pv_shop_slug', 
        'meta_value'        => '',
        'meta_key'          => 'location', 
        'meta_value'        => $location,
        'meta_key'          => 'organization', 
        'meta_value'        => $org,
        'orderby'           => $orderby,
        'order'             => $order,
    );

    if ($show_products == 'yes') $vendor_total_args['query_id'] = 'vendors_with_products'; 
    $vendor_query = New WP_User_Query( $vendor_total_args ); 
    $all_vendors =$vendor_query->get_results(); 

    ob_start();

    // Loop through all vendors and output a simple link to their vendor pages
    foreach ($all_vendors as $vendor) {
        dokan_get_template( 'vendor-list.php', array(
            'shop_link'         => Dokan_Vendors::get_vendor_shop_page($vendor->ID), 
            'shop_name'         => $vendor->pv_shop_name, 
            'vendor_id'         => $vendor->ID, 
            'shop_description'  => $vendor->pv_shop_description, 
        ), 'dokan-vendors/front/', wcv_plugin_dir . 'templates/front/' );
    } // End foreach 

    $html .= '<ul class="dokan_vendorslist">' . ob_get_clean() . '</ul>';
    return $html; 
}
add_shortcode('dokan_vendors_location', 'dokan_vendors_location');

/* END */

但是现在当我将简码插入我的网站时,我看到一个空白区域。

我在这段代码中做错了什么?

4

0 回答 0