如何将wordpress/php函数应用于特定的产品类别
Re。Wordpress,WooCommerce,Woo订阅 我想使用下面的函数()隐藏某些“操作”按钮,但我只想将其应用于我的wordpress产品的一个类别 我该怎么做如何将wordpress/php函数应用于特定的产品类别,php,wordpress,woocommerce,Php,Wordpress,Woocommerce,Re。Wordpress,WooCommerce,Woo订阅 我想使用下面的函数()隐藏某些“操作”按钮,但我只想将其应用于我的wordpress产品的一个类别 我该怎么做 <?php * Remove the "Change Payment Method" button from the My Subscriptions table. * * This isn't actually necessary because @see eg_subscription_payment_met
<?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订阅管理页面,而不是实际的Woocommerce产品页面(它会有一个类别)。试试这个
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 );
你是Zipkundan。不幸的是,这不起作用。如果我删除if语句,代码就会工作,因此我认为可能没有正确地将category ID返回给函数。我应该考虑针对特定的产品ID而不是类别ID吗?(重复)我在原始描述中添加了更多的信息。我担心,由于显示按钮的页面与woocommerce订阅/订单相关,原始产品的类别将不可用。
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 );