{"id":16975008,"date":"2023-08-15T17:28:54","date_gmt":"2023-08-15T17:28:54","guid":{"rendered":"https:\/\/wordpress.org\/support\/topic\/monthly-invoices-not-generated\/"},"modified":"2023-08-15T17:28:54","modified_gmt":"2023-08-15T17:28:54","slug":"monthly-invoices-not-generated","status":"publish","type":"topic","link":"https:\/\/wordpress.org\/support\/topic\/monthly-invoices-not-generated\/","title":{"rendered":"monthly invoices not generated"},"content":{"rendered":"\n<p class=\"wp-block-paragraph\">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?<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>\/\/ Send PDF Invoice only for Internal products \/\/ add_filter( 'wpo_wcpdf_document_is_allowed', function( $condition, $document ) { if ( $document-&gt;type == 'invoice' ) { if ( $document-&gt;exists() ) { return $condition; } $condition = false; if ( $order = $document-&gt;order ) { \/\/Set categories here (comma separated) $not_allowed_cats = array( 'internal-products' ); $order_cats = array(); \/\/Get order categories foreach ( $order-&gt;get_items() as $item_id =&gt; $item ) { \/\/ get categories for item, requires product if ( $product = $item-&gt;get_product() ) { $id = $product-&gt;get_parent_id() ? $product-&gt;get_parent_id() : $product-&gt;get_id(); $terms = get_the_terms( $id, 'product_cat' ); if ( empty( $terms ) ) { continue; } else { foreach ( $terms as $key =&gt; $term ) { $order_cats&#091;$term-&gt;term_id] = $term-&gt;slug; } } } } \/\/ get array of category matches $cat_matches = array_intersect( $not_allowed_cats, $order_cats ); if ( count( $cat_matches ) &gt; 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-&gt;data&#091;'status'] == 'processing') { $virtual_order = null; if ( count( $order-&gt;get_items() ) &gt; 0 ) { foreach( $order-&gt;get_items() as $item ) { if ( 'line_item' == $item&#091;'type'] ) { $_product = $order-&gt;get_product_from_item( $item ); if ( ! $_product-&gt;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-&gt;update_status( 'completed' ); } } }<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\"><\/p>\n","protected":false},"template":"","class_list":["post-16975008","topic","type-topic","status-publish","hentry"],"jetpack_sharing_enabled":true,"_links":{"self":[{"href":"https:\/\/wordpress.org\/support\/wp-json\/wp\/v2\/topic\/16975008","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/wordpress.org\/support\/wp-json\/wp\/v2\/topic"}],"about":[{"href":"https:\/\/wordpress.org\/support\/wp-json\/wp\/v2\/types\/topic"}],"version-history":[{"count":0,"href":"https:\/\/wordpress.org\/support\/wp-json\/wp\/v2\/topic\/16975008\/revisions"}],"wp:attachment":[{"href":"https:\/\/wordpress.org\/support\/wp-json\/wp\/v2\/media?parent=16975008"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}