• Resolved FlashUK

    (@flashuk)


    Hi,

    I am currently developing a WooCommerce multi-store website, and I was hoping to use your plugin to generate the necessary PDFs.

    Really like the plugin by the way. Works really well ??

    Currently, I am using WC Vendors to accomplish this – but I want to add the “PDF Invoice” button to where the Shop Owner have incoming orders.

    I can easily add a button, like you suggest in your FAQ, to the necessary page, but I am blocked by these lines of code in the generate_pdf_ajax function.

    includes/class-wcpdf-export.php, line: 446

    
    // Check if current user is owner of order IMPORTANT!!!
    if ( $this->order->user_id != get_current_user_id() ) {
    	wp_die( __( 'You do not have sufficient permissions to access this page.', 'wpo_wcpdf' ) );
    }
    

    This is obviously very important code (don’t want to spill the beans on anyone’s details!)

    I kindly ask if you could add a custom filter that I can plug into to allow additional checks?

    Any filter name would do, something like this would be perfect:

    
    // Check if current user is owner of order IMPORTANT!!!
    if ( apply_filters('wpo_wcpdf_check_owner_priv', $this->order->user_id != get_current_user_id() ) ) {
    	wp_die( __( 'You do not have sufficient permissions to access this page.', 'wpo_wcpdf' ) );
    }
    

    That way, I can check if the order belongs to the vendor so they can also download the generated invoice for packing purposes.

    I hope you can implement this – I’m sure there are other developers would also want to use this.

    Cheers ??

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

    (@pomegranate)

    Hi! This is actually already possible!
    Check this thread: https://github.com/wcvendors/wcvendors/issues/196#issuecomment-138639644

    Let me know if you need anything else for this!
    Ewout

    Thread Starter FlashUK

    (@flashuk)

    Thank you for linking the code snippet, didn’t find that while I was googling!

    Very useful ??

    It makes more sense than what I put – I realise you just drop the ref to “my-account” which allows you to adjust the permissions.

    FYI, anyone else using WC Vendors Pro who wants to add the buttons to the “Order” dashboard section, use the code below:

    
    add_filter('wcv_orders_add_new_row', function($new_row){
    	if ( !class_exists( 'WooCommerce_PDF_Invoices' ) ) {
    		return false;
    	}
    	$order_id = $new_row->order_number;
    	$order = new WC_Order ( $order_id );
    
    	$vendor_pdf_actions = array(
    		'invoice'       => array (
    			'class'     => 'button tips wpo_wcpdf invoice',
    			'url'       => wp_nonce_url( admin_url( 'admin-ajax.php?action=generate_wpo_wcpdf&template_type=invoice&order_ids=' . $order->id ), 'generate_wpo_wcpdf' ),
    			'label'		=> sprintf( '<img src="%s" width="16">', WooCommerce_PDF_Invoices::$plugin_url . 'images/invoice.png'),
    			'target'    => '_blank'
    		),
    		'packing-slip'       => array (
    			'class'     => 'button tips wpo_wcpdf packing-slip',
    			'url'       => wp_nonce_url( admin_url( 'admin-ajax.php?action=generate_wpo_wcpdf&template_type=packing-slip&order_ids=' . $order->id ), 'generate_wpo_wcpdf' ),
    			'label'		=> sprintf( '<img src="%s" width="16">', WooCommerce_PDF_Invoices::$plugin_url . 'images/packing-slip.png'),
    			'target'    => '_blank'
    		),
    	);
    
    	$new_row->row_actions = array_merge($new_row->row_actions, $vendor_pdf_actions);
    
    	return $new_row;
    }, 10, 1);
    

    Cheers!

    jaypreet

    (@jaypreet)

    Hello Flash UK,

    I am weak in coding and cannot do anything without guidance. Please tell me where to enter this code which file and line.

    Also I have WC pro and do i need to have Woocommerce pdf invoices packaginf free version or premium version .

    Thanks for your guidance in advance.

    thanks

    Daniel Mesteru

    (@daniel-mesteru)

    Hello,

    Great work, thank you for this very useful snippet. I’ve added this code to my functions.php file, the buttons are showing correctly in vendor dashboard but when I click on them, I receive the following error message:
    You do not have permission to access this page.

    The path resulted on button trigger is this:
    /wp-admin/admin-ajax.php?action=generate_wpo_wcpdf&template_type=invoice&order_ids=3684&_wpnonce=3f81c785ab

    Any idea of what could be the cause of this?

    Thanks,
    Daniel

Viewing 4 replies - 1 through 4 (of 4 total)
  • The topic ‘New filter for generate_pdf_ajax’ is closed to new replies.