• Resolved yashshah1800

    (@yashshah1800)


    I have marked the invoice to be downloadable and seen only when the order is in complete status. It looks like its not working as the invoice is downloadable even when the order is in processing state.

    I want the invoice no to be incremented and seen and downloadable only when the order is in complete status. Plz guide. Thank you,

Viewing 3 replies - 1 through 3 (of 3 total)
  • Thread Starter yashshah1800

    (@yashshah1800)

    I got this resolved using the following:
    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();
    debug_to_console(“order stauts”);
    debug_to_console($order_status);

    // set allowed order statuses (slugs, so ‘on-hold’ instead of ‘On Hold’)
    $allowed_statuses = array( ‘completed’);

    // remove button/link status not allowed
    if ( !in_array($order_status, $allowed_statuses) ) {
    unset( $actions[‘invoice’]);
    }

    return $actions;
    }

    Plugin Contributor Ewout

    (@pomegranate)

    Hello,
    The setting on the General settings tab only affects the My Account page, if you want to disable the buttons on the admin pages too then indeed you need a snippet like yours. For anyone else who wants the same thing, I recommend removing the debug_to_console lines:

    
    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 );
    
    	// set allowed order statuses (slugs, so 'on-hold' instead of 'On Hold')
    	$allowed_statuses = array( 'completed' );
    
    	// remove button/link status not allowed
    	if ( !in_array($order->get_status(), $allowed_statuses) ) {
    		unset( $actions['invoice'] );
    	}
    
    	return $actions;
    }
    
    Thread Starter yashshah1800

    (@yashshah1800)

    Thanks .

Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘Invoice is downloadable on any order status’ is closed to new replies.