Support » Plugin: Code Snippets » How do I execute snippet after plugins are loaded?

  • Resolved jwjo

    (@jwjo)


    Hi there,

    I am basically trying to change the ‘Read more’ button text on the Shop page (Category page) when an item is out of stock to ‘Join the waitlist’ instead.

    However, as I have a Custom Fields plugin installed as well, it seems to change the button text to ‘View Product’.

    I already have a snippet below, which I’ve tested and does work. However, the moment I activate the Custom Fields plugin, it seems to get a higher priority and will display the button text as ‘View Product’.

    // For all products 
    add_filter( 'woocommerce_product_add_to_cart_text', 'product_single_add_to_cart_text_filter_callback', 100, 2 );
    function product_single_add_to_cart_text_filter_callback( $button_text, $product ) {
        if( ! $product->is_in_stock() ) {
            $button_text = __("Join the waitlist", "woocommerce");
        }
        return $button_text;
    }

    Is there any way or workaround where I can force the snippet to have a higher priority than the plugin so that the ‘Join the waitlist’ text can be displayed instead?

    I am a complete rookie and don’t really have any idea what I’m doing. Any help or advice would be greatly appreciated. Thanks so much in advance!

    Kind regards,
    E

Viewing 1 replies (of 1 total)
  • Plugin Author Shea Bunge

    (@bungeshea)

    Hi E,

    You can increase the priority of an action hook by increasing the number in the third argument to the add_filter function call:

    add_filter( 'woocommerce_product_add_to_cart_text', 'product_single_add_to_cart_text_filter_callback', 10000, 2 );

    Additionally, I would recommend using an anonymous function instead of a named function like so:

    add_filter( 'woocommerce_product_add_to_cart_text', function ( $button_text, $product ) {
    
    	if ( ! $product->is_in_stock() ) {
    		$button_text = __( 'Join the waitlist', 'woocommerce' );
    	}
    
    	return $button_text;
    
    }, 10000, 2 );
Viewing 1 replies (of 1 total)
  • The topic ‘How do I execute snippet after plugins are loaded?’ is closed to new replies.