尝试在woocommerce add_action挂钩中调用add_filter时遇到问题。当用户第一次注册时,我必须添加自定义费用,如果他已经登录并升级其会员资格,那么我想删除这些费用。过滤器正在运行,但它会删除第一次注册以及升级的费用。我在结帐页面上调用它,但它不起作用。这是我的代码。
function my_remove_signup_fee( $subscription_sign_up_fee, $product ) {
$subscription_sign_up_fee =0;
return $subscription_sign_up_fee;
}
add_action('woocommerce_cart_totals_after_billing', 'action_cart_calculate_totals');
function action_cart_calculate_totals( $cart_object ) {
//echo "<pre>";
//print_r($cart_object);
if ( is_admin() && ! defined( 'DOING_AJAX' ) )
return;
if ( !WC()->cart->is_empty() ):
foreach( WC()->cart->get_cart() as $cart_item ){
$product_id = $cart_item['product_id'];
}
$subfeeArr = get_post_meta( $product_id,'_subscription_sign_up_fee');
if(!empty($subfeeArr)){
$subfee = current($subfeeArr);
}else{
$subfee =0;
}
$current_user = wp_get_current_user();
$userEmail = $current_user->user_email;
$mydb = new wpdb('lbmls_c1lbmlsu','qprn230','lbmls_c1lbmls','mysql01.landbrokermls.com');
$query = "SELECT id FROM users WHERE email = '{$userEmail}' AND com = '1' AND `Coop-Fee` = '1'";
$rows = $mydb->get_results($query,ARRAY_A);
if(!empty($rows)){
$userId = current($rows);
if($userId!=""){
return add_filter( 'woocommerce_subscriptions_product_sign_up_fee', 'my_remove_signup_fee', 10, 2 );
}
}
endif;
}