WooCommerce多供应商市场从产品ID获取供应商ID

时间:2019-04-30 08:50:10

标签: woocommerce vendor

我在Wordpress中使用WooCommerce Multivendor Marketplace插件进行多供应商站点。我想限制用户,以便他们只能在购物车中添加一个供应商的产品。我正在编写一个自定义函数来获取供应商ID。

我正在尝试使用get_wcfm_product_vendors函数,但是它不起作用;我认为它可能不受支持。我正在寻找其他可能的解决方案,但找不到任何解决方案。我还可以使用其他任何方法来获取产品的供应商ID吗?

1 个答案:

答案 0 :(得分:0)

您可以尝试WCFM单供应商结帐功能,将此代码添加到您的子主题中:



    add_action( 'woocommerce_add_to_cart_validation', function( $is_allow, $product_id, $quantity ) {
    $product = get_post( $product_id );
    $product_author = $product->post_author;
    //Iterating through each cart item
    foreach ( WC()->cart->get_cart() as $cart_item_key => $cart_item ) {
    $cart_product_id = $cart_item['product_id'];
    $cart_product = get_post( $cart_product_id );
    $cart_product_author = $cart_product->post_author;
    if( $cart_product_author != $product_author ) {
    $is_allow = false;
    break;
    }
    }
    if( !$is_allow ){
    // We display an error message
    wc_clear_notices();
    wc_add_notice( __( "Well, you already have some item in your cart. First checkout with those and then purchase other items!", "wcfm" ), 'error' );
    }
    return $is_allow;
    }, 50, 3 );

https://docs.wclovers.com/tweaks/#single-vendor-checkout