php - Woocommerce 中按位置简码列出的 Dokan 供应商列表
问题描述
我想允许我的 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 */
但是现在当我将简码插入我的网站时,我看到一个空白区域。
我在这段代码中做错了什么?
解决方案
推荐阅读
- php - 如何使用 cURL 和 PHP 从使用 SSL 的网站获取数据?
- flutter - 我想在一个容器中显示 ListView,它的大小随着列表项的增加而动态增加
- iis - 按 Header 值列出的 IIS 白名单
- marklogic - 有没有办法在 MarkLogic 中以优化的方式为所有数据库安排备份?
- python - python子进程函数找不到路径:php文件
- time-complexity - 动态规划中记忆递归与表法的时间复杂度比较
- c# - While 循环中的“System.Argument.Exception 参数无效”位图错误
- python - 如何在重定向视图中获取 kwargs 值
- smartcard - 有没有办法重置个人识别码 (PIN) 尝试计数器?(标签 0x9F17)
- javascript - 使用 POS 打印机打印 Javascript 收据只打印标题部分我想打印实际文本