禁用特定用户元数据的 WooCommerce 结帐支付

Disable WooCommerce checkout payment for specific user meta data

我的客户希望允许某些特定客户事后通过发票付款。 所以我在用户配置文件中添加了一个额外的字段,他可以在其中 select yes/no。 此字段工作正常并正确保存。

取决于选择: 否 = 默认网上商店行为和客户需要直接付款。 yes = 客户可以在不付款的情况下订购商品,他稍后会收到发票。

也尝试了不同的支付方式,但每个人都可以使用,我只希望特定用户使用。

现在我已经尝试基于 functions.php 中的那个字段添加条件过滤器,如下所示:

if (esc_attr( get_the_author_meta( 'directbetalen', $user->ID ) ) == 'no') {
    add_filter('woocommerce_cart_needs_payment', '__return_false');
}

但是好像不行?

我希望在字段设置为 no 时跳过付款。 否则照常进行,客户需要付款。

使用 WordPress get_user_meta() 功能,尝试以下操作:

add_filter( 'woocommerce_cart_needs_payment', 'disable_payment_for_specific_users' );
function show_specific_payment_method_for_specific_users( $needs_payment ) {
    if ( get_user_meta( get_current_user_id(), 'directbetalen', true ) === 'no' ) {
        $needs_payment = false;
    }
    return $needs_payment;
}

代码进入您的活动子主题(或活动主题)的 functions.php 文件。它应该可以工作。