2016-04-08 11 views
0

Re。 Wordpress、WooCommerce、Woo Subscriptions特定の製品カテゴリにwordpress/php関数を適用する方法

特定の「アクション」ボタンを非表示にするには、以下の機能(https://gist.github.com/thenbrent/8851287)を使用したいと思いますが、これは私のワードプレス製品の1つのカテゴリにしか適用しません。

どうすればよいですか?

<?php 
* Remove the "Change Payment Method" button from the My Subscriptions table. 
* 
* This isn't actually necessary because @see eg_subscription_payment_method_cannot_be_changed() 
* will prevent the button being displayed, however, it is included here as an example of how to 
* remove just the button but allow the change payment method process. 
*/ 
function eg_remove_my_subscriptions_button($actions, $subscription) { 
    foreach ($actions as $action_key => $action) { 
     switch ($action_key) { 
      case 'change_payment_method': // Hide "Change Payment Method" button? 
//   case 'change_address':  // Hide "Change Address" button? 
//   case 'switch':   // Hide "Switch Subscription" button? 
//   case 'resubscribe':  // Hide "Resubscribe" button from an expired or cancelled subscription? 
//   case 'pay':   // Hide "Pay" button on subscriptions that are "on-hold" as they require payment? 
//   case 'reactivate':  // Hide "Reactive" button on subscriptions that are "on-hold"? 
//   case 'cancel':   // Hide "Cancel" button on subscriptions that are "active" or "on-hold"? 
       unset($actions[ $action_key ]); 
       break; 
      default: 
       error_log('-- $action = ' . print_r($action, true)); 
       break; 
     } 
    } 
    return $actions; 
} 
add_filter('wcs_view_subscription_actions',  'eg_remove_my_subscriptions_button', 100, 2); 

さらに詳しい情報:

問題のページはWooCommerceサブスクリプションが付属していますビューのサブスクリプション・ページである:以下/個人用サイト/私のアカウント/ビューのサブスクリプション/ 4606/

提案私たちが実際にWoocommerceのサブスクリプションの男を見ているので、私は、これは動作しません心配

$cat_id = $wp_query->get_queried_object()->term_id; // get current category id). 

:例えば、現在のカテゴリのIDを取得するに基づいています実際のWoocommerce製品ページではありません(カテゴリを持つことになります)。

答えて

0

はそれあなたZipkundanこの

function eg_remove_my_subscriptions_button($actions, $subscription) { 
    global $wp_query; 
    $cat_id = $wp_query->get_queried_object()->term_id; // get current category id 

    if($cat_id == 26) { // check if we're in the category 
       foreach ($actions as $action_key => $action) { 
      switch ($action_key) { 
       case 'change_payment_method': // Hide "Change Payment Method" button? 
    //   case 'change_address':  // Hide "Change Address" button? 
    //   case 'switch':   // Hide "Switch Subscription" button? 
    //   case 'resubscribe':  // Hide "Resubscribe" button from an expired or cancelled subscription? 
    //   case 'pay':   // Hide "Pay" button on subscriptions that are "on-hold" as they require payment? 
    //   case 'reactivate':  // Hide "Reactive" button on subscriptions that are "on-hold"? 
    //   case 'cancel':   // Hide "Cancel" button on subscriptions that are "active" or "on-hold"? 
        unset($actions[ $action_key ]); 
        break; 
       default: 
        error_log('-- $action = ' . print_r($action, true)); 
        break; 
      } 
     } 

    } 
    return $actions; 
} 
add_filter('wcs_view_subscription_actions', 'eg_remove_my_subscriptions_button', 100, 2); 
+0

を試してみてください。残念ながら、これは動作しません。 if文を削除するとコードが機能するので、カテゴリIDが関数に正しく返されていない可能性があります。カテゴリIDの代わりに特定の商品IDをターゲットに設定することを検討する必要がありますか? –

+0

(繰り返し)元の説明にもう少し詳しい情報を追加しました。私は、ボタンを表示するページは、woocommerceのサブスクリプション/オーダーに関連しているため、元の製品のカテゴリは利用できないことを恐れています。 –

関連する問題