Search code examples
phpwordpresswoocommercewoocommerce-subscriptions

WooCommerce Subscriptions: Remove "Browse products" button on my account page


I want to remove the "Browse Products" button on the subscription page of My account area.

I found the output in the template file my-subscriptions.php. But there is no filter to remove it without editing the template file.

Is there any other way to do that? Maybe there is a way to change the link of the button (to a specific product) and the text?

This is the code for the link:

<a class="woocommerce-Button button" href="<?php echo esc_url( apply_filters( 'woocommerce_return_to_shop_redirect', wc_get_page_permalink( 'shop' ) ) ); ?>">
    <?php esc_html_e( 'Browse products', 'woocommerce-subscriptions' ); ?>
</a>

Solution

  • add_action( 'wp_head', 'hide_browse_product_element', 100 );
    
    function hide_browse_product_element() {
        echo "<style> .no_subscriptions{display:none;} </style>";
    }
    

    Try this code snippet

    If you want to change the text without overriding the template, try this

    function change_browse_product_element( $translated_text, $text, $domain ) {
        switch ( $translated_text ) {
            case 'Browse products' :
                $translated_text = __( 'My Button Text', 'woocommerce' );
                break;
        }
        return $translated_text;
    }
    
    add_filter( 'gettext', 'change_browse_product_element', 20, 3 );
    

    From here

    To change the link, please use the code below.

    add_filter( 'woocommerce_return_to_shop_redirect', 'mujuonly_redirect_browse_product' );
    
    function mujuonly_redirect_browse_product( $url ) {
        return "https://www.google.com";
    }