如何从woocommerce中禁用购物车功能?

时间:2015-03-28 05:54:57

标签: wordpress woocommerce

如何从woocommerce商店禁用购物车功能。我希望用户只能看到可用的产品。客户无法从商店购买。

3 个答案:

答案 0 :(得分:7)

最简单的方法是让产品不可购买..

add_filter( 'woocommerce_is_purchasable','__return_false',10,2);

答案 1 :(得分:0)

要完全禁用woocommerce购买功能:

add_filter( 'woocommerce_is_purchasable', '__return_false'); // DISABLING PURCHASE FUNCTIONALITY AND REMOVING ADD TO CART BUTTON FROM NORMAL PRODUCTS

remove_action('woocommerce_single_variation', 'woocommerce_single_variation', 10); // REMOVING PRICE FROM VARIATIONS

remove_action('woocommerce_single_variation', 'woocommerce_single_variation_add_to_cart_button', 20); // REMOVING ADD TO CART BUTTON FROM VARIATIONS

您可以在这里找到更多选项:https://react2wp.com/remove-hide-add-to-cart-button-in-woocommerce-while-disabling-keeping-purchase-functionality/

答案 2 :(得分:0)

如果需要条件,可以使用以下代码:

function m3wc_woocommerce_is_purchasable( $is_purchasable, $product ) {
    // Conditions here.

    return $is_purchasable;
}
add_filter( 'woocommerce_is_purchasable', 'm3wc_woocommerce_is_purchasable', 10, 2 );

例如,如果您需要检查用户:

// Disable purchase for non-logged-in users.
function m3wc_woocommerce_is_purchasable( $is_purchasable, $product ) {
    if ( ! is_user_logged_in() ) {
        return false;
    }

    return $is_purchasable;
}
add_filter( 'woocommerce_is_purchasable', 'm3wc_woocommerce_is_purchasable', 10, 2 );