Php WCFM商业市场-忽略当前产品

Php WCFM商业市场-忽略当前产品,php,wordpress,woocommerce,marketplace,Php,Wordpress,Woocommerce,Marketplace,我正在使用插件并在Elementor主题中构建单一产品页面。我想显示供应商的产品,WCFM包含一个短码[products store=“id”],它是标准WooCommerce[产品]短码的一部分 我询问WCFM开发人员是否有办法将存储ID动态添加到短代码中,他们提供了以下代码: add_shortcode('wcfm_store_related_products','fn_wcfm_store_related_products'); function fn_wcfm_store_related

我正在使用插件并在Elementor主题中构建单一产品页面。我想显示供应商的产品,WCFM包含一个短码[products store=“id”],它是标准WooCommerce[产品]短码的一部分

我询问WCFM开发人员是否有办法将存储ID动态添加到短代码中,他们提供了以下代码:

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 columns="5" limit="10" store="'.$store_id.'"]');
}
这是可行的,但是当添加到单个产品页面时,它也会显示当前产品


我想做的是忽略当前产品(不要显示)。有人知道我会怎么做吗?

我不知道WC产品是否有产品的
排除
参数,但您可以使用WC
woocommerce\u shortcode\u products\u query
过滤器挂钩,您可以根据需要更改参数,检查下面的代码

function remove_current_prodcut_woocommerce_shortcode_products_query( $query_args, $attributes, $type ){
    global $post;
    if( is_product() ){
        $query_args['post__not_in'] = array($post->ID);
    }
    return $query_args;
}
add_filter( 'woocommerce_shortcode_products_query', 'remove_current_prodcut_woocommerce_shortcode_products_query', 10, 3 );

谢谢,我试过了,但是它删除了[products]快捷码创建的所有产品。天哪,你太棒了!这非常有效-非常感谢你!!