我正在将WooCommerce与WCFM Marketplace插件一起使用。我正在想办法在供应商的商店页面上显示不同类别的供应商产品。
例如:
蔬菜(类别(
产品|产品|产品|
FRUITS(类别(
产品|产品|产品|
我知道他们已经有了一个带有供应商类别的小部件侧边栏,但我希望页面上有如上所示的部分。在我的脑海里,它就像";对于每个供应商类别->展示该类别中的产品";。
您可以将此片段添加到您的子主题中:
add_shortcode('wcfm_store_related_products','fn_wcfm_store_related_products');
function fn_wcfm_store_related_products($attr) {
global $WCFM, $WCFMmp, $wp, $WCFM_Query, $post;
$store_id = '';
if ( isset( $attr['id'] ) && !empty( $attr['id'] ) ) { $store_id = absint($attr['id']); }
if ( wcfm_is_store_page() ) {
$wcfm_store_url = get_option( 'wcfm_store_url', 'store' );
$store_name = apply_filters( 'wcfmmp_store_query_var', get_query_var( $wcfm_store_url ) );
$store_id = 0;
if ( !empty( $store_name ) ) {
$store_user = get_user_by( 'slug', $store_name );
}
$store_id = $store_user->ID;
}
if( is_product() ) {
$store_id = $post->post_author;
}
if( !$store_id && is_single() && $post && is_object( $post ) && wcfm_is_vendor( $post->post_author ) ) {
$store_id = $post->post_author;
}
echo do_shortcode('[products category="t-shirt" store="'.$store_id.'"]');
}
按短代码使用:[wcfm_store_related_products]