id !== $order_screen && 'woocommerce_page_wc-orders' !== $screen->id ) ) { return; } $net = esc_js( __( 'Network error.', 'factella' ) ); $js = "jQuery(function($){ $(document).on('click','.factella-pdp-send',function(){var b=$(this);var box=b.closest('.factella-pdp-box');" . "b.prop('disabled',true);box.find('.factella-pdp-msg').css('color','#646970').text('…');" . "$.post(ajaxurl,{action:'factella_pdp_send_now',nonce:b.data('nonce'),order_id:b.data('order'),refund_id:b.data('refund')||0},function(res){" . "b.prop('disabled',false);var m=res&&res.data&&res.data.message?res.data.message:'';" . "if(res&&res.data&&res.data.badge){box.find('.factella-pdp-badge').html(res.data.badge);}" . "box.find('.factella-pdp-msg').css('color',res&&res.success?'#1a7f37':'#d63638').text(m);" . "}).fail(function(){b.prop('disabled',false);box.find('.factella-pdp-msg').css('color','#d63638').text('$net');});});});"; wp_add_inline_script( 'jquery-core', $js ); } /** * Register the meta box on whichever order screen is active. */ public static function add_meta_box() { $screen = function_exists( 'wc_get_page_screen_id' ) ? wc_get_page_screen_id( 'shop-order' ) : 'shop_order'; add_meta_box( 'efacture-fr-invoice', __( 'Invoice (Factella)', 'factella' ), array( __CLASS__, 'render_meta_box' ), $screen, 'side', 'high' ); } /** * Render the meta box. * * @param WP_Post|WC_Order $post_or_order Post (legacy) or order (HPOS). */ public static function render_meta_box( $post_or_order ) { $order = $post_or_order instanceof WC_Order ? $post_or_order : wc_get_order( $post_or_order->ID ); if ( ! $order ) { return; } $number = (string) $order->get_meta( EFacture_FR_Invoice_Manager::META_NUMBER ); $buyer = EFacture_FR_Checkout_Fields::get_buyer_ids( $order ); if ( '' === $number ) { echo '
' . esc_html__( 'No invoice yet. It will be created automatically when the order reaches the configured status.', 'factella' ) . '
'; } else { echo '' . esc_html__( 'Number:', 'factella' ) . ' ' . esc_html( $number ) . '
';
echo '' . esc_html__( 'Date:', 'factella' ) . ' ' . esc_html( (string) $order->get_meta( EFacture_FR_Invoice_Manager::META_DATE ) ) . '
';
echo '' . esc_html__( 'Type:', 'factella' ) . ' ' . esc_html( (string) $order->get_meta( EFacture_FR_Invoice_Manager::META_TYPE ) ) . '
' . esc_html__( 'Download Factur-X PDF', 'factella' ) . '
'; } } // SUPER PDP transmission status + manual send. if ( '' !== $number && class_exists( 'EFacture_FR_Transmission' ) ) { $type = (string) $order->get_meta( EFacture_FR_Invoice_Manager::META_TYPE ); echo '' . esc_html__( 'SUPER PDP:', 'factella' ) . ' '; echo EFacture_FR_Transmission::badge_html( $order ); // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped -- self-escaped badge markup. echo '
'; if ( 'B2C' === $type ) { echo '' . esc_html__( 'B2C — covered by e-reporting, not transmitted.', 'factella' ) . '
'; } else { $nonce = wp_create_nonce( 'factella_pdp_send_now' ); echo ''; } echo '
';
if ( '' !== $buyer['siret'] ) {
echo 'SIRET: ' . esc_html( $buyer['siret'] ) . '
';
echo 'SIREN: ' . esc_html( $buyer['siren'] ) . '
';
}
if ( '' !== $buyer['vat'] ) {
echo '' . esc_html__( 'VAT:', 'factella' ) . ' ' . esc_html( $buyer['vat'] );
}
echo '
' . esc_html( sprintf( __( 'Credit note: %s', 'factella' ), $credit ) );
if ( $facturx ) {
echo '
'
. esc_html__( 'Download credit note PDF', 'factella' ) . '';
}
echo '