How to hide certain menu like PAYMENT SETTINGS based on product ID?

31 Views Asked by At

How to hide certain menu like PAYMENT SETTINGS based on product ID that subscriber pay for?

I know how to hide button based on the product ID, but I don't know how to hide certain menu based on product ID.

Can check image here

Please help because I'm stuck.

function eg_remove_my_subscriptions_button( $actions, $subscription ) {

    $is_my_product = false;
    $specific_products = array( 108150 , 108154 , 108144 , 108157  );
    if ( sizeof( $subscription_items = $subscription->get_items() ) > 0 ) {
        foreach ( $subscription_items as $item_id => $item ) {
            $product = $item->get_product();
            if ( in_array( $product->get_id(), $specific_products ) ) {
                $is_my_product = true;
                break;
            }
        }
    }

    if ( !$is_my_product ) return $actions;

    foreach ( $actions as $action_key => $action ) {
        switch ( $action_key ) {
            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( 'woocommerce_my_account_my_orders_actions', 'eg_remove_my_subscriptions_button', 100, 2 );
  • This code is to hide certain button in subscription based on product ID.
  • I want to hide certain menu like PAYMENT SETTINGS based on product ID. Can check image here.
0

There are 0 best solutions below