• The plugin WC Vendors allows WooCommerce stores to have multiple vendors which add products and fulfill orders. They are given the role “vendor”. If your PDF plugin had a few extra filters, it could be possible to allow vendors to be able to print PDF invoices and packing slips.

    This discussion is currently happening at WC Vendors’ Github here: https://github.com/wcvendors/wcvendors/issues/196

    We need to add a way to generate links to download PDF invoices and packing slips. Currently if I copy your code:
    wp_nonce_url( admin_url( 'admin-ajax.php?action=generate_wpo_wcpdf&template_type=packing-slip&order_ids=' . $order->id ), 'generate_wpo_wcpdf' )
    I can generate a link for my vendors, but your plugin will prevent vendors from getting the PDF based on a user permission check that occurs in WooCommerce_PDF_Invoices_Export->generate_pdf_ajax()
    If this check (the 3rd one) had a filter on it, I could hook into that and check to see if the user is a vendor, then allow them access if they pass that check. For example:

    public function generate_pdf_ajax() {
    	// Check the nonce
    	if( empty( $_GET['action'] ) || ! is_user_logged_in() || !check_admin_referer( $_GET['action'] ) ) {
    		wp_die( __( 'You do not have sufficient permissions to access this page.', 'wpo_wcpdf' ) );
    	}
    
    	// Check if all parameters are set
    	if( empty( $_GET['template_type'] ) || empty( $_GET['order_ids'] ) ) {
    		wp_die( __( 'Some of the export parameters are missing.', 'wpo_wcpdf' ) );
    	}
    
    	$order_ids = (array) explode('x',$_GET['order_ids']);
    	// Process oldest first: reverse $order_ids array
    	$order_ids = array_reverse($order_ids);
    
    	// Check the user privileges
    	if( apply_filters( 'wpo_wcpdf_check_privs', !current_user_can( 'manage_woocommerce_orders' ) && !current_user_can( 'edit_shop_orders' ) && !isset( $_GET['my-account'] ), $order_ids ) ) {
    		wp_die( __( 'You do not have sufficient permissions to access this page.', 'wpo_wcpdf' ) );
    	}

    Note: I’m moving the 3rd check to fire later on so that we can pass it $order_ids, which might come in handy.

    There’s two other issues, but I’m not exactly sure that they require any change to your plugin at this point.

    Thanks

    https://wordpress.org/plugins/woocommerce-pdf-invoices-packing-slips/

Viewing 3 replies - 1 through 3 (of 3 total)
  • Good stuff. Would love to see this plugin implement these changes.

    Thread Starter GoTeamScotch

    (@goteamscotch)

    I’ve Already Forked your plugin on github and made a few changes. If I make a pull request is there a good chance we could see that implemented on a future release? I’m going to be doing the work already for my site and I’m more than willing to share the work.

    Plugin Contributor Ewout

    (@pomegranate)

    Hi! I’ve added this to the plugin, and it will be included in the next release! Commit 5cf17a6085b8204b77db7dd30dddd558846f5413

    Note that I currently do not have plans to integrate WC Vendors into core without support for child orders. This is because besides the regular item list and totals in the simple template, the plugin supports a lot of other more specific order requests which would return faulty totals when performed on the main order. If you need any action hooks or filters for more convenient compatibility I can probably add them for you though. I’ll also look into providing WCVendors with a pull request with a soft (backwards compatible) introduction of child orders.

    Let me know if you have any other questions!

    Ewout

Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘Additional Filters Needed’ is closed to new replies.