• Resolved WeDev.Africa

    (@mad2kx)


    Hi guys, I am using this custom script to generate monthly invoices for a subscription product on my multivendor store. For the past 3 months the invoices are no longer auto-generated. I have to do this manually. A bit difficult with +300 vendors. I was wondering how I can check if the cron runs or how I can setup a custom cron for this on Plesk instead of using WP Cron?

    // Send PDF Invoice only for Internal products // add_filter( 'wpo_wcpdf_document_is_allowed', function( $condition, $document ) { if ( $document->type == 'invoice' ) { if ( $document->exists() ) { return $condition; } $condition = false; if ( $order = $document->order ) { //Set categories here (comma separated) $not_allowed_cats = array( 'internal-products' ); $order_cats = array(); //Get order categories foreach ( $order->get_items() as $item_id => $item ) { // get categories for item, requires product if ( $product = $item->get_product() ) { $id = $product->get_parent_id() ? $product->get_parent_id() : $product->get_id(); $terms = get_the_terms( $id, 'product_cat' ); if ( empty( $terms ) ) { continue; } else { foreach ( $terms as $key => $term ) { $order_cats[$term->term_id] = $term->slug; } } } } // get array of category matches $cat_matches = array_intersect( $not_allowed_cats, $order_cats ); if ( count( $cat_matches ) > 0 ) { return true; // if there is 1 or more matches: allow invoice } } } return $condition; }, 10, 2 ); // Auto Complete all virtual orders add_action('woocommerce_order_status_changed', 'ts_auto_complete_virtual'); function ts_auto_complete_virtual($order_id) { if ( ! $order_id ) { return; } global $product; $order = wc_get_order( $order_id ); if ($order->data['status'] == 'processing') { $virtual_order = null; if ( count( $order->get_items() ) > 0 ) { foreach( $order->get_items() as $item ) { if ( 'line_item' == $item['type'] ) { $_product = $order->get_product_from_item( $item ); if ( ! $_product->is_virtual() ) { // once we find one non-virtual product, break out of the loop $virtual_order = false; break; } else { $virtual_order = true; } } } } // if all are virtual products, mark as completed if ( $virtual_order ) { $order->update_status( 'completed' ); } } }

Viewing 6 replies - 1 through 6 (of 6 total)
  • Plugin Contributor alexmigf

    (@alexmigf)

    Hi @mad2kx

    Can you paste your code here and without being in 1 line only?

    Thread Starter WeDev.Africa

    (@mad2kx)

    Hi @alexmigf ,

    sorry not sure what happened here. Here’s the PasteBin

    Plugin Contributor alexmigf

    (@alexmigf)

    Looking at your code doesn’t seem that they do any kind of Invoice generation.

    The first it’s just a condition to allow the invoice to be generated for specific products, and the second changes the order status on virtual products condition.

    Thread Starter WeDev.Africa

    (@mad2kx)

    As mentioned, the invoice generation was automatically done in the past but somehow stopped about 3 months ago. I can manually trigger them 1 by 1 from the backend but with 300+ vendors it is a mission. Hence my assumption that the cron for this is stuck, I just don’t know the cron name for this?

    Plugin Contributor alexmigf

    (@alexmigf)

    Our plugin doesn’t have a “automatic” Invoice generation cron. You can attach the Invoice to emails and when those are triggered the document is generated or you can generate it manually.

    Saying that, I’m not sure which cron are you referring to, but from your first email it seems that someone created a custom snippet, which you didn’t share with us at the moment, because the ones you showed aren’t about that.

    Plugin Contributor Yordan Soares

    (@yordansoares)

    Hi @mad2kx,

    Since we haven’t heard back from you in the last two weeks, we’re assuming you solved this issue, so I’ll go ahead and mark this ticket as Resolved.

    Feel free to reply to this topic is you still need help with this, or open a new topic if you have any other questions!

Viewing 6 replies - 1 through 6 (of 6 total)
  • The topic ‘monthly invoices not generated’ is closed to new replies.