r > 0 ) { /* translators: 1. document type, 2. mark/unmark */ wp_die( sprintf( esc_html__( 'Document of type %1$s for the selected order could not be %2$s as printed.', 'woocommerce-pdf-invoices-packing-slips' ), esc_attr( $data['document_type'] ), $event_type ) ); } } /** * Check if a document is printed * * @return bool */ public function is_document_printed( $document ) { $is_printed = false; if ( ! empty( $document ) && ! empty( $order = $document->order ) ) { if ( 'shop_order' === $order->get_type() && ! empty( $printed_data = $order->get_meta( "_wcpdf_{$document->slug}_printed" ) ) ) { $is_printed = true; } } return $is_printed; } /** * Check if a document can be manually marked as printed * * @return bool */ public function document_can_be_manually_marked_printed( $document ) { $can_be_manually_marked_printed = false; if ( empty( $document ) || ( property_exists( $document, 'is_bulk' ) && $document->is_bulk ) ) { return $can_be_manually_marked_printed; } $document->save_settings(); $can_be_manually_marked_printed = false; $document_exists = is_callable( array( $document, 'exists' ) ) ? $document->exists() : false; $document_printed = $document_exists && is_callable( array( $document, 'printed' ) ) ? $document->printed() : false; $triggers = isset( $document->latest_settings['mark_printed'] ) && is_array( $document->latest_settings['mark_printed'] ) ? $document->latest_settings['mark_printed'] : []; $manually_print_enabled = in_array( 'manually', $triggers ) ? true : false; if ( $document_exists && ! $document_printed && $manually_print_enabled ) { $can_be_manually_marked_printed = true; } return apply_filters( 'wpo_wcpdf_document_can_be_manually_marked_printed', $can_be_manually_marked_printed, $document ); } /** * Get document printed data * * @return array */ public function get_document_printed_data( $document ) { $data = []; if ( ! empty( $document ) && $this->is_document_printed( $document ) && ! empty( $order = $document->order ) ) { if ( 'shop_order' === $order->get_type() && ! empty( $printed_data = $order->get_meta( "_wcpdf_{$document->slug}_printed" ) ) ) { $data = $printed_data; } } return apply_filters( 'wpo_wcpdf_document_printed_data', $data, $document ); } /** * Enable PHP error output */ public function enable_debug () { error_reporting( E_ALL ); ini_set( 'display_errors', 1 ); } public function wc_webhook_topic_hooks( $topic_hooks, $wc_webhook ) { $documents = WPO_WCPDF()->documents->get_documents(); foreach ($documents as $document) { $topic_hooks["order.{$document->type}-saved"] = array( "wpo_wcpdf_webhook_order_{$document->slug}_saved", ); } return $topic_hooks; } public function wc_webhook_topic_events( $topic_events ) { $documents = WPO_WCPDF()->documents->get_documents(); foreach ($documents as $document) { $topic_events[] = "{$document->type}-saved"; } return $topic_events; } public function wc_webhook_topics( $topics ) { $documents = WPO_WCPDF()->documents->get_documents(); foreach ($documents as $document) { /* translators: document title */ $topics["order.{$document->type}-saved"] = esc_html( sprintf( __( 'Order %s Saved', 'woocommerce-pdf-invoices-packing-slips' ), $document->get_title() ) ); } return $topics; } public function wc_webhook_trigger( $document, $order ) { do_action( "wpo_wcpdf_webhook_order_{$document->slug}_saved", $order->get_id() ); } /** * @param null|string $document_type * @param null|\WC_Order|\WC_Order_Refund $order * * @return void */ public function display_due_date( string $document_type = null, $order = null ): void { if ( empty( $order ) || empty( $document_type ) ) { return; } $document = wcpdf_get_document( $document_type, $order ); if ( ! $document ) { return; } $due_date_timestamp = is_callable( array( $document, 'get_due_date' ) ) ? $document->get_due_date() : 0; if ( 0 >= $due_date_timestamp ) { return; } $due_date = apply_filters( 'wpo_wcpdf_due_date_display', date_i18n( wcpdf_date_format( $this, 'due_date' ), $due_date_timestamp ), $due_date_timestamp, $document_type, $document ); $due_date_title = is_callable( array( $document, 'get_due_date_title' ) ) ? $document->get_due_date_title() : __( 'Due Date:', 'woocommerce-pdf-invoices-packing-slips' ); if ( ! empty( $due_date ) ) { echo ' ', $due_date_title, ' ', $due_date, ' '; } } } endif; // class_exists