2017-03-07 5 views
0

私はYITH WooCommerce購読を使用しています。カートに購読があるかどうかを確認したい支払い用ゲートウェイの1つを無効にします。どうすればいいですか?YITH WooCommerce Subscription Wordpressでカートに有効な購読があるか確認してください

私はすでにこのコードを試していますが、これは機能しません。あなただけのすべてのテストしたい場合は https://makersbyte.com/check-active-subscriptions-using-yith-woocommerce/

:で

function CheckSubscriptionByEmail($email) { 

     // getting all the records of the user by email for the subscription 
     $subscriptions = get_posts(array(
      'numberposts' => -1, 
      'post_type' => 'ywsbs_subscription', // Subscription post type 
      'orderby' => 'post_date', // ordered by date 
      'order' => 'ASC', 
      'meta_query' => array(
      array(
       'key' => '_billing_email', //additional fields being used to get the data 
       'value' => $email, 
       'compare' => '=' 
      ), 
      array(
       'key' => '_status', 
       'value' => 'active', //active subscriptions 
       'compare' => '=' 
      )) 
     )); 

     // check if user has any active subscription 
     foreach ($subscriptions as $post) : setup_postdata($post); 
      $nextdue = get_post_meta(get_the_id(), '_payment_due_date',true); 
      $current_date = date("Y-m-d"); 
      $date_to_compare = date("Y-m-d",strtotime($nextdue)); 
      if (strtotime($date_to_compare) > strtotime($current_date)) { 
       echo "active"; //returns active 
       break; 
      } 
     endforeach; 
     wp_reset_postdata(); 

    } 

Referneceと説明:

add_filter('woocommerce_available_payment_gateways', 'filter_gateways', 1); 
function filter_gateways($gateways){ 

    if (has_woocommerce_subscription('','','active')) { 
     unset($gateways['pin_payments']); 
    } 
    return $gateways; 
} 

function has_woocommerce_subscription($the_user_id, $the_product_id, $the_status) { 
    $current_user = wp_get_current_user(); 
    if (empty($the_user_id)) { 
     $the_user_id = $current_user->ID; 
    } 
    if (WC_Subscriptions_Manager::user_has_subscription($the_user_id, $the_product_id, $the_status)) { 
     return true; 
    } 
} 

答えて

0

あなたは2つの質問を持っているが、一つは、あなたがこの機能を経由してテストすることができますアクティブなサブスクリプションであります上記の関数を次のように変更します。

 $subscriptions = get_posts(array(
      'numberposts' => -1, 
      'post_type' => 'ywsbs_subscription', // Subscription post type 
      'orderby' => 'post_date', // ordered by date 
      'order' => 'ASC', 
      'meta_query' => array(
      array(
       'key' => '_status', 
       'value' => 'active', //active subscriptions 
       'compare' => '=' 
      )) 
     )); 

アクティブなサブスクリプションのリストを取得したら、必要に応じて無効にすることはかなりストレートで簡単です。

支払ゲートウェイ、単に銀行振込 - >チェックアウト>すべての決済ゲートウェイが一覧表示されます。これを使用して無効にします。

関連する問題