Viewing 5 replies - 1 through 5 (of 5 total)
  • Plugin Contributor Ewout

    (@pomegranate)

    Hi Elsappy,
    That code only works for english installs. However, in newer versions there’s a much better way of doing this. Add the following to your themes functions.php:

    /**
     * Remove invoice button from admin and customer my account
     */
    add_filter( 'wpo_wcpdf_listing_actions', 'wpo_wcpdf_remove_invoice', 20, 1 );
    add_filter( 'wpo_wcpdf_myaccount_actions', 'wpo_wcpdf_remove_invoice', 20, 1 );
    add_filter( 'wpo_wcpdf_meta_box_actions', 'wpo_wcpdf_remove_invoice', 20, 1 );
    add_filter( 'wpo_wcpdf_bulk_actions', 'wpo_wcpdf_remove_invoice', 20, 1 );
    
    function wpo_wcpdf_remove_invoice ($actions) {
    	if ( isset($actions['invoice']) ) {
    		unset( $actions['invoice']);
    	}
    	return $actions;
    }

    Hope that helps!

    May I ask which plugin you are using for invoices and why you think it’s better?

    Thanks!
    Ewout

    Thread Starter elsappy

    (@elsappy)

    Thanks a lot for your answer.
    Unfortunately the code doesn’t work ?? I tried to disable some plugins but I didn’t find any conflict.
    (I’m using a custom-made plugin)

    Plugin Contributor Ewout

    (@pomegranate)

    That’s very strange, I tested the code on my development installation and it works as expected… Which version are you using? Did you get an error or did it just not do anything?

    Thread Starter elsappy

    (@elsappy)

    My apologies, I don’t know what happened but the code works fine !
    Thanks Ewout ??

    Plugin Contributor Ewout

    (@pomegranate)

    For anyone looking to do this for specific order statuses:

    /**
     * Remove invoice button for certain statuses
     */
    add_filter( 'wpo_wcpdf_listing_actions', 'wpo_wcpdf_disable_invoice', 20, 2 );
    add_filter( 'wpo_wcpdf_myaccount_actions', 'wpo_wcpdf_disable_invoice', 20, 2 );
    add_filter( 'wpo_wcpdf_meta_box_actions', 'wpo_wcpdf_disable_invoice', 20, 2 );
    function wpo_wcpdf_disable_invoice ( $actions, $order ) {
        // make sure $order is the actual order object
        $order = wc_get_order( $order );
        $order_status = $order->get_status();
        // set allowed order statuses (slugs, so 'on-hold' instead of 'On Hold')
        $allowed_statuses = array( 'completed','processing' );
    
        // remove button/link status not allowed
        if ( !in_array($order_status, $allowed_statuses) ) {
            unset( $actions['invoice']);
        }
    
        return $actions;
    }

    If you haven’t edited your theme functions before, read this first: How to use filters

    Ewout

Viewing 5 replies - 1 through 5 (of 5 total)
  • The topic ‘Disable invoice function’ is closed to new replies.