• Resolved tdw02d

    (@tdw02d)


    Does anyone know how I can add multiple product ids to this snippet? Whenever I try to duplicate it my page breaks, so I guess I have no other option.

    Here is the code:

    add_filter( 'woocommerce_order_button_text', 'misha_custom_button_text_for_product' );
     
    function misha_custom_button_text_for_product( $button_text ) {
     
    	$product_id = 505; // a specific product ID you would like to check
     
    	if( WC()->cart->find_product_in_cart( WC()->cart->generate_cart_id( $product_id ) ) ) {
    		$button_text = 'New Button Text';
    	}
     
    	return $button_text;
     
    }
Viewing 1 replies (of 1 total)
  • Plugin Author Shea Bunge

    (@bungeshea)

    You can add a loop to your snippet to check multiple product IDs:

    add_filter( 'woocommerce_order_button_text', function ( $button_text ) {
    
    	// a list of specific product IDs you would like to check
    	$product_ids = [ 505, 42, 301, 419 ];
    
    	foreach ( $product_ids as $product_id ) {
    		$cart_id = WC()->cart->generate_cart_id( $product_id );
    		
    		if ( WC()->cart->find_product_in_cart( $cart_id ) ) {
    			return 'New Button Text';
    		}
    	}
    	
    	return $button_text;
    } );
Viewing 1 replies (of 1 total)
  • The topic ‘Add multiple product_ids to a snippet?’ is closed to new replies.