sections = apply_filters( 'wpo_ips_edi_settings_sections', array(
'settings' => __( 'Settings', 'woocommerce-pdf-invoices-packing-slips' ),
'identifiers' => __( 'Identifiers', 'woocommerce-pdf-invoices-packing-slips' ),
'taxes' => __( 'Taxes', 'woocommerce-pdf-invoices-packing-slips' ),
'network' => __( 'Network', 'woocommerce-pdf-invoices-packing-slips' ),
) );
add_action( 'admin_init', array( $this, 'init_settings' ) );
add_action( 'wpo_wcpdf_settings_output_edi', array( $this, 'output_settings' ), 10, 2 );
add_action( 'woocommerce_order_after_calculate_totals', array( $this, 'save_taxes_on_calculate_order_totals' ), 10, 2 );
add_action( 'woocommerce_checkout_order_processed', array( $this, 'save_taxes_on_checkout' ), 10, 3 );
add_filter( 'pre_update_option_wpo_ips_edi_settings', array( $this, 'preserve_peppol_settings' ), 10, 3 );
// AJAX
add_action( 'wp_ajax_wpo_ips_edi_save_taxes', array( $this, 'ajax_save_taxes' ) );
add_action( 'wp_ajax_wpo_ips_edi_reload_tax_table', array( $this, 'ajax_reload_tax_table' ) );
add_action( 'wp_ajax_wpo_ips_edi_load_customer_order_identifiers', array( $this, 'ajax_load_customer_order_identifiers' ) );
}
/**
* Output the settings for EDI.
*
* @param string $active_section
* @param string $nonce
*
* @return void
*/
public function output_settings( string $active_section, string $nonce ): void {
if ( ! wp_verify_nonce( $nonce, 'wp_wcpdf_settings_page_nonce' ) ) {
return;
}
$active_section = ! empty( $active_section ) ? $active_section : 'settings';
?>
sections ) > 1 ) : ?>
sections as $section => $title ) {
$active = ( $section === $active_section ) ? 'nav-tab-active' : '';
printf(
'%4$s',
esc_url( add_query_arg( 'section', $section ) ),
esc_attr( $section ),
esc_attr( $active ),
wp_kses_post( $title )
);
}
?>
sections[ $active_section ] ); ?>
output_supplier_identifiers();
$this->output_customer_identifiers();
break;
case 'taxes':
$this->output_taxes();
break;
case 'network':
$this->output_network();
break;
}
do_action( 'wpo_ips_edi_settings_after_output', $active_section, $this->sections );
}
/**
* Initialize the settings for EDI.
*
* @return void
*/
public function init_settings(): void {
$page = $option_group = $option_name = 'wpo_ips_edi_settings';
$section = 'edi';
$settings_fields = array(
array(
'type' => 'section',
'id' => $section,
'title' => '',
'callback' => 'section',
),
array(
'type' => 'setting',
'id' => 'enabled',
'title' => __( 'Enable Electronic Documents', 'woocommerce-pdf-invoices-packing-slips' ),
'callback' => 'checkbox',
'section' => $section,
'args' => array(
'option_name' => $option_name,
'id' => 'enabled',
'description' => __( 'Allow your store to generate and send electronic documents.', 'woocommerce-pdf-invoices-packing-slips' ),
)
),
array(
'type' => 'setting',
'id' => 'syntax',
'title' => __( 'Preferred Syntax', 'woocommerce-pdf-invoices-packing-slips' ),
'callback' => 'select',
'section' => $section,
'args' => array(
'option_name' => $option_name,
'id' => 'syntax',
'options' => wpo_ips_edi_syntaxes(),
'description' => sprintf(
/* translators: %s: link to documentation */
__( 'Choose the preferred XML syntax standard for electronic documents. Need help deciding? %s', 'woocommerce-pdf-invoices-packing-slips' ),
'' . __( 'See the format comparison guide', 'woocommerce-pdf-invoices-packing-slips' ) . ''
),
),
),
);
$settings_format = array();
foreach ( wpo_ips_edi_syntax_formats() as $syntax => $data ) {
$description = sprintf(
/* translators: %s syntax */
__( 'Choose the preferred %s format.', 'woocommerce-pdf-invoices-packing-slips' ),
strtoupper( trim( $syntax ) )
);
if ( 'cii' === strtolower( trim( $syntax ) ) && ! class_exists( 'WCPDF_Custom_PDF_Maker_mPDF' ) ) {
$description .= ' ' . sprintf(
/* translators: %1$s: open link anchor, %2$s: close link anchor */
__( 'The %1$smPDF extension%2$s is required for hybrid formats. Please install or enable it.', 'woocommerce-pdf-invoices-packing-slips' ),
'',
''
);
}
$settings_format[] = array(
'type' => 'setting',
'id' => "{$syntax}_format",
'title' => '',
'callback' => 'select',
'section' => $section,
'args' => array(
'title' => __( 'Format', 'woocommerce-pdf-invoices-packing-slips' ),
'option_name' => $option_name,
'id' => "{$syntax}_format",
'options' => array_combine(
array_keys( $data['formats'] ),
array_column( $data['formats'], 'name' )
),
'description' => wp_kses_post( $description ),
'custom_attributes' => array(
'data-show_for_option_name' => $option_name . '[syntax]',
'data-show_for_option_values' => json_encode( array( $syntax ) ),
),
),
);
}
if ( ! empty( $settings_format ) ) {
$settings_fields = array_merge( $settings_fields, $settings_format );
}
// Peppol specific field
$settings_fields[] = array(
'type' => 'setting',
'id' => 'peppol_endpoint_id',
'title' => '',
'callback' => 'text_input',
'section' => $section,
'args' => array(
'title' => __( 'Peppol Endpoint ID', 'woocommerce-pdf-invoices-packing-slips' ),
'option_name' => $option_name,
'id' => 'peppol_endpoint_id',
'description' => sprintf(
'%s
%s',
__( 'Specify the Peppol Endpoint ID for the supplier. Do not include the scheme (e.g., "0208:"), as it can be selected below.', 'woocommerce-pdf-invoices-packing-slips' ),
sprintf(
/* translators: %1$s: open link anchor, %2$s: close link anchor */
__( 'If you don\'t know the ID, you can search for it in the %1$sPeppol Directory%2$s.', 'woocommerce-pdf-invoices-packing-slips' ),
'',
''
)
),
'custom_attributes' => array(
'data-show_for_option_name' => $option_name . '[ubl_format]',
'data-show_for_option_values' => json_encode( array( 'peppol-bis-3p0' ) ),
'data-keep_current_value' => true,
),
),
);
// Peppol specific field
$settings_fields[] = array(
'type' => 'setting',
'id' => 'peppol_endpoint_eas',
'title' => '',
'callback' => 'select',
'section' => $section,
'args' => array(
'title' => __( 'Peppol Endpoint Scheme (EAS)', 'woocommerce-pdf-invoices-packing-slips' ),
'option_name' => $option_name,
'id' => 'peppol_endpoint_eas',
'options' => ( function () {
$options = array( '' => __( 'Select', 'woocommerce-pdf-invoices-packing-slips' ) . '...' );
foreach ( EN16931::get_eas() as $code => $label ) {
$options[ $code ] = "[$code] $label";
}
return $options;
} )(),
'description' => sprintf(
'%s
%s',
__( 'Specify the Electronic Address Scheme (EAS) for the supplier Endpoint above.', 'woocommerce-pdf-invoices-packing-slips' ),
sprintf(
/* translators: %1$s: open link anchor, %2$s: close link anchor */
__( 'For more information on each Endpoint Address Scheme (EAS), refer to the %1$sofficial Peppol EAS list%2$s.', 'woocommerce-pdf-invoices-packing-slips' ),
'',
''
)
),
'custom_attributes' => array(
'data-show_for_option_name' => $option_name . '[ubl_format]',
'data-show_for_option_values' => json_encode( array( 'peppol-bis-3p0' ) ),
'data-keep_current_value' => true,
),
),
);
// Peppol specific field
$settings_fields[] = array(
'type' => 'setting',
'id' => 'peppol_endpoint_id_field_location',
'title' => '',
'callback' => 'select',
'section' => $section,
'args' => array(
'title' => __( 'Customer Peppol Endpoint ID field location', 'woocommerce-pdf-invoices-packing-slips' ),
'option_name' => $option_name,
'id' => 'peppol_endpoint_id_field_location',
'default' => 'none',
'options' => array(
'none ' => __( 'None', 'woocommerce-pdf-invoices-packing-slips' ),
'checkout' => __( 'Checkout only', 'woocommerce-pdf-invoices-packing-slips' ),
'my_account' => __( 'My Account only', 'woocommerce-pdf-invoices-packing-slips' ),
'both' => __( 'Both Checkout and My Account', 'woocommerce-pdf-invoices-packing-slips' ),
),
'description' => __( 'Controls where the Customer Peppol Endpoint ID field is displayed.', 'woocommerce-pdf-invoices-packing-slips' ),
'custom_attributes' => array(
'data-show_for_option_name' => $option_name . '[ubl_format]',
'data-show_for_option_values' => json_encode( array( 'peppol-bis-3p0' ) ),
'data-keep_current_value' => true,
),
),
);
// Peppol specific field
if ( defined( 'WC_VERSION' ) && version_compare( WC_VERSION, '9.9.0', '>=' ) ) {
$settings_fields[] = array(
'type' => 'setting',
'id' => 'peppol_endpoint_id_checkout_visibility',
'title' => '',
'callback' => 'select',
'section' => $section,
'args' => array(
'title' => __( 'Customer Peppol Endpoint ID field visibility', 'woocommerce-pdf-invoices-packing-slips' ),
'option_name' => $option_name,
'id' => 'peppol_endpoint_id_checkout_visibility',
'default' => 'always',
'options' => array(
'always' => __( 'Always', 'woocommerce-pdf-invoices-packing-slips' ),
'toggle' => __( 'On business purchase selection', 'woocommerce-pdf-invoices-packing-slips' ),
'company' => __( 'When company name is present', 'woocommerce-pdf-invoices-packing-slips' ),
),
'description' => __( 'Controls when the customer Peppol Endpoint ID field is shown at checkout.', 'woocommerce-pdf-invoices-packing-slips' ),
'custom_attributes' => array(
'data-show_for_option_name' => $option_name . '[peppol_endpoint_id_field_location]',
'data-show_for_option_values' => wp_json_encode( array( 'checkout', 'both' ) ),
'data-keep_current_value' => true,
),
),
);
}
// Peppol specific field
$settings_fields[] = array(
'type' => 'setting',
'id' => 'peppol_directory_validation',
'title' => '',
'callback' => 'checkbox',
'section' => $section,
'args' => array(
'title' => __( 'Validate Customer Peppol Endpoint ID', 'woocommerce-pdf-invoices-packing-slips' ),
'option_name' => $option_name,
'id' => 'peppol_directory_validation',
'description' => __(
'When enabled, the customer Peppol Endpoint ID entered at checkout or in the My Account area is validated against the Peppol Directory. If no matching participant is found, an error is shown so the value can be corrected.',
'woocommerce-pdf-invoices-packing-slips'
),
'custom_attributes' => array(
'data-show_for_option_name' => $option_name . '[ubl_format]',
'data-show_for_option_values' => wp_json_encode( array( 'peppol-bis-3p0' ) ),
'data-keep_current_value' => true,
),
),
);
// Peppol specific field
$settings_fields[] = array(
'type' => 'setting',
'id' => 'peppol_automatic_endpoint_id_derivation',
'title' => '',
'callback' => 'checkbox',
'section' => $section,
'args' => array(
'title' => __( 'Automatic Peppol Endpoint ID derivation', 'woocommerce-pdf-invoices-packing-slips' ),
'option_name' => $option_name,
'id' => 'peppol_automatic_endpoint_id_derivation',
'description' => sprintf(
/* translators: %s: link to documentation */
__( 'Automatically generate Peppol IDs from VAT numbers for supported countries. This can help ensure the correct format and reduce errors. %s', 'woocommerce-pdf-invoices-packing-slips' ),
'' . __( 'Learn more', 'woocommerce-pdf-invoices-packing-slips' ) . ''
),
'custom_attributes' => array(
'data-show_for_option_name' => $option_name . '[ubl_format]',
'data-show_for_option_values' => wp_json_encode( array( 'peppol-bis-3p0' ) ),
'data-keep_current_value' => true,
),
),
);
$mappings = wpo_ips_edi_get_peppol_vat_mappings();
$countries = array();
if ( is_array( $mappings ) ) {
foreach ( $mappings as $code => $data ) {
if ( empty( $data['name'] ) || empty( $data['eas'] ) ) {
continue;
}
$countries[ $code ] = sprintf( '%s [%s]', $data['name'], $data['eas'] );
}
}
asort( $countries, SORT_NATURAL | SORT_FLAG_CASE );
// Peppol specific field
$settings_fields[] = array(
'type' => 'setting',
'id' => 'peppol_automatic_endpoint_id_derivation_countries',
'title' => '',
'callback' => 'select',
'section' => $section,
'args' => array(
'title' => __( 'Select countries for deriving the Peppol Endpoint ID', 'woocommerce-pdf-invoices-packing-slips' ),
'option_name' => $option_name,
'id' => 'peppol_automatic_endpoint_id_derivation_countries',
'options' => $countries,
'multiple' => true,
'enhanced_select' => true,
'placeholder' => __( 'Select one or more countries', 'woocommerce-pdf-invoices-packing-slips' ),
'class' => 'edi-multiple',
'custom_attributes' => array(
'data-show_for_option_name' => $option_name . '[peppol_automatic_endpoint_id_derivation]',
'data-show_for_option_values' => wp_json_encode( array( '1' ) ),
'data-keep_current_value' => true,
),
),
);
// Peppol specific field.
$settings_fields[] = array(
'type' => 'setting',
'id' => 'peppol_checkout_script_type',
'title' => '',
'callback' => 'select',
'section' => $section,
'args' => array(
'title' => __( 'Checkout Script Loading', 'woocommerce-pdf-invoices-packing-slips' ),
'option_name' => $option_name,
'id' => 'peppol_checkout_script_type',
'default' => 'auto',
'options' => array(
'auto' => __( 'Automatic detection', 'woocommerce-pdf-invoices-packing-slips' ),
'classic' => __( 'Force classic checkout scripts', 'woocommerce-pdf-invoices-packing-slips' ),
'block' => __( 'Force block checkout scripts', 'woocommerce-pdf-invoices-packing-slips' ),
),
'description' => __(
'Use this only if the Peppol Endpoint ID derivation scripts are not loading correctly on the checkout page. Leave it on Automatic detection unless you are experiencing issues.',
'woocommerce-pdf-invoices-packing-slips'
),
'custom_attributes' => array(
'data-show_for_option_name' => $option_name . '[peppol_automatic_endpoint_id_derivation]',
'data-show_for_option_values' => wp_json_encode( array( '1' ) ),
'data-keep_current_value' => true,
),
),
);
$languages = wpo_wcpdf_get_multilingual_languages();
if ( count( $languages ) > 0 ) {
$settings_fields[] = array(
'type' => 'setting',
'id' => 'supplier_identifiers_language',
'title' => __( 'Supplier Identifiers Language', 'woocommerce-pdf-invoices-packing-slips' ),
'callback' => 'select',
'section' => $section,
'args' => array(
'option_name' => $option_name,
'id' => 'supplier_identifiers_language',
'options' => $languages,
'description' => sprintf(
/* translators: %1$s: open link anchor, %2$s: close link anchor */
__( 'Select the language for the supplier identifiers data. This option is available because multilingual support is enabled. You can check the currently available data %1$shere%2$s.', 'woocommerce-pdf-invoices-packing-slips' ),
'',
''
),
)
);
}
$settings_fields[] = array(
'type' => 'setting',
'id' => 'embed_encrypted_pdf',
'title' => '',
'callback' => 'checkbox',
'section' => $section,
'args' => array(
'title' => __( 'Embed Encrypted PDF', 'woocommerce-pdf-invoices-packing-slips' ),
'option_name' => $option_name,
'id' => 'embed_encrypted_pdf',
'description' => __( 'Embed the encrypted PDF invoice file within the e-document.', 'woocommerce-pdf-invoices-packing-slips' ),
'custom_attributes' => array(
'data-show_for_option_name' => $option_name . '[syntax]',
'data-show_for_option_values' => json_encode( array( 'ubl' ) ),
),
)
);
$settings_fields[] = array(
'type' => 'setting',
'id' => 'send_attachments',
'title' => __( 'Send Attachments', 'woocommerce-pdf-invoices-packing-slips' ),
'callback' => 'checkbox',
'section' => $section,
'args' => array(
'option_name' => $option_name,
'id' => 'send_attachments',
'description' => __( 'When sending a document by e-mail, automatically include the electronic version attachment along with the PDF.', 'woocommerce-pdf-invoices-packing-slips' ),
),
);
$settings_fields[] = array(
'type' => 'setting',
'id' => 'include_item_meta',
'title' => __( 'Include Item Meta Data', 'woocommerce-pdf-invoices-packing-slips' ),
'callback' => 'checkbox',
'section' => $section,
'args' => array(
'option_name' => $option_name,
'id' => 'include_item_meta',
'description' => sprintf(
'%s %s',
__( 'Include item meta data in the e-document.', 'woocommerce-pdf-invoices-packing-slips' ),
sprintf(
/* translators: 1: opening link tag, 2: closing link tag */
__( 'Advanced customization is possible, see the %1$sdocumentation page%2$s for details.', 'woocommerce-pdf-invoices-packing-slips' ),
'',
''
)
),
)
);
$settings_fields[] = array(
'type' => 'setting',
'id' => 'enabled_preview',
'title' => __( 'Enable XML Preview', 'woocommerce-pdf-invoices-packing-slips' ),
'callback' => 'checkbox',
'section' => $section,
'args' => array(
'option_name' => $option_name,
'id' => 'enabled_preview',
'description' => __( 'Enable the XML preview for electronic documents.', 'woocommerce-pdf-invoices-packing-slips' ),
)
);
$settings_fields[] = array(
'type' => 'setting',
'id' => 'enabled_logs',
'title' => __( 'Enable Debug Logs', 'woocommerce-pdf-invoices-packing-slips' ),
'callback' => 'checkbox',
'section' => $section,
'args' => array(
'option_name' => $option_name,
'id' => 'enabled_logs',
'description' => __( 'Enable logging for debugging purposes.', 'woocommerce-pdf-invoices-packing-slips' ),
)
);
$settings_fields = apply_filters( 'wpo_ips_edi_settings', $settings_fields, $page, $option_group, $option_name );
WPO_WCPDF()->settings->add_settings_fields( $settings_fields, $page, $option_group, $option_name );
}
/**
* Preserve Peppol settings on update.
*
* @param mixed $value
* @param mixed $old_value
* @param string $option
*
* @return array
*/
public function preserve_peppol_settings( $value, $old_value, string $option ): array {
$new = is_array( $value ) ? $value : array();
$old = is_array( $old_value ) ? $old_value : array();
foreach ( $new as $key => $val ) {
if ( false !== strpos( $key, 'peppol_' ) ) {
// preserve old value on empty new value
if ( empty( $val ) && ! empty( $old[ $key ] ) ) {
$new[ $key ] = $old[ $key ];
// normalize endpoint ID
} elseif ( ! empty( $val ) && 'peppol_endpoint_id' === $key ) {
$new[ $key ] = preg_replace( '/^[^:]+:/', '', trim( $val ) );
}
}
}
return $new;
}
/**
* Save taxes on calculate order totals.
*
* @param bool $and_taxes
* @param \WC_Abstract_Order $order
*
* @return void
*/
public function save_taxes_on_calculate_order_totals( bool $and_taxes, \WC_Abstract_Order $order ): void {
// it seems $and_taxes is mostly false, meaning taxes are calculated separately,
// but we still update just in case anything changed
wpo_ips_edi_save_order_taxes( $order );
}
/**
* Save taxes on checkout.
*
* @param int $order_id
* @param array $posted_data
* @param \WC_Order $order
*
* @return void
*/
public function save_taxes_on_checkout( int $order_id, array $posted_data, \WC_Order $order ): void {
wpo_ips_edi_save_order_taxes( $order );
wpo_ips_edi_maybe_save_order_peppol_data( $order, $posted_data );
}
/**
* Get setting value by key.
*
* @param string $key
* @param mixed $default
* @return mixed
*/
public function get_setting( string $key, $default = null ) {
$settings = get_option( 'wpo_ips_edi_settings', array() );
if ( isset( $settings[ $key ] ) ) {
return $settings[ $key ];
}
return $default;
}
/**
* Load customer identifiers via AJAX.
*
* @return void
*/
public function ajax_load_customer_order_identifiers(): void {
if ( ! check_ajax_referer( 'wpo_ips_edi_nonce', 'nonce', false ) ) {
wp_send_json_error( __( 'Invalid nonce.', 'woocommerce-pdf-invoices-packing-slips' ) );
}
$request = stripslashes_deep( $_GET );
$order_id = absint( $request['order_id'] );
if ( empty( $order_id ) ) {
wp_send_json_error( __( 'Order ID is required.', 'woocommerce-pdf-invoices-packing-slips' ) );
}
$order = wc_get_order( $order_id );
if ( empty( $order ) ) {
wp_send_json_error( __( 'Order not found!', 'woocommerce-pdf-invoices-packing-slips' ) );
}
$data = wpo_ips_edi_get_order_customer_identifiers_data( $order );
wp_send_json_success( compact( 'data' ) );
}
/**
* Save taxes from AJAX request.
*
* @return void
*/
public function ajax_save_taxes(): void {
$nonce = isset( $_POST['nonce'] ) ? sanitize_text_field( wp_unslash( $_POST['nonce'] ) ) : '';
if (
! isset( $_POST['action'] ) ||
'wpo_ips_edi_save_taxes' !== $_POST['action'] ||
! wp_verify_nonce( $nonce, 'edi_save_taxes' )
) {
wp_send_json_error( __( 'Invalid request.', 'woocommerce-pdf-invoices-packing-slips' ) );
}
$request = stripslashes_deep( $_POST );
$tax_settings = isset( $request['wpo_ips_edi_tax_settings'] ) ? $request['wpo_ips_edi_tax_settings'] : array();
$this->save_tax_settings( $tax_settings );
wp_send_json_success( __( 'Tax settings saved successfully.', 'woocommerce-pdf-invoices-packing-slips' ) );
}
/**
* Reload the tax table via AJAX.
*
* @return void
*/
public function ajax_reload_tax_table(): void {
if ( ! check_ajax_referer( 'wpo_ips_edi_nonce', 'nonce', false ) ) {
wp_send_json_error( __( 'Invalid nonce.', 'woocommerce-pdf-invoices-packing-slips' ) );
}
$request = stripslashes_deep( $_GET );
$tax_class = isset( $request['tax_class'] ) ? sanitize_text_field( $request['tax_class'] ) : '';
ob_start();
$this->output_table_for_tax_class( $tax_class );
$html = ob_get_clean();
echo $html; // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
wp_die();
}
/**
* Output supplier identifiers.
*
* @return void
*/
private function output_supplier_identifiers(): void {
$identifiers_data = wpo_ips_edi_get_supplier_identifiers_data();
foreach ( $identifiers_data as $language_slug => $language_data ) :
?>
[]
$data ) {
$value = $data['value'];
$required = $data['required'];
$display = $value ?: sprintf(
'%s',
$required ? '#d63638' : '#996800',
$required
? esc_html__( 'Missing', 'woocommerce-pdf-invoices-packing-slips' )
: esc_html__( 'Optional', 'woocommerce-pdf-invoices-packing-slips' )
);
?>
|
|
|
' . esc_html__( 'Shop Information', 'woocommerce-pdf-invoices-packing-slips' ) . ''
); ?>
|
__( 'Standard rate', 'woocommerce-pdf-invoices-packing-slips' )
);
// Woo 5.2+
if ( is_callable( array( '\WC_Tax', 'get_tax_rate_classes' ) ) ) {
$rates = \WC_Tax::get_tax_rate_classes();
foreach ( $rates as $rate ) {
if ( empty( $rate->slug ) ) {
continue;
}
$formatted_rates[ $rate->slug ] = ! empty( $rate->name ) ? $rate->name : $rate->slug;
}
// Older Woo versions
} else {
$slugs = \WC_Tax::get_tax_class_slugs();
$names = \WC_Tax::get_tax_classes();
foreach ( $slugs as $i => $slug ) {
if ( empty( $slug ) ) {
continue;
}
$name = ! empty( $names[ $i ] ) ? $names[ $i ] : $slug;
$formatted_rates[ $slug ] = $name;
}
}
?>
output_tax_class_selector_and_action( $formatted_rates ); // Output tax class selector and action button ?>
$name ) : ?>
output_table_for_tax_class( $slug ); ?>
$name ) :
$is_active = ( $slug === $current_slug );
$active_class = $is_active ? 'active' : '';
$href = add_query_arg( 'edi_tax_class', $slug ); // graceful fallback
?>
-
',
''
);
?>
output_tax_selector_for( 'scheme', 'class', $slug, $scheme ); ?>
:
output_tax_selector_for( 'category', 'class', $slug, $category ); ?>
:
output_tax_selector_for( 'reason', 'class', $slug, $reason ); ?>
:
prefix}woocommerce_tax_rates";
$slug = sanitize_key( strtolower( $slug ) );
$query = wpo_wcpdf_prepare_identifier_query(
"SELECT * FROM %i WHERE tax_rate_class = %s ORDER BY tax_rate_country ASC, tax_rate_state ASC;",
array( $table_name ),
array( ( 'standard' === $slug ) ? '' : $slug )
);
$results = $wpdb->get_results( $query ); // phpcs:ignore WordPress.DB.DirectDatabaseQuery.DirectQuery, WordPress.DB.DirectDatabaseQuery.NoCaching, WordPress.DB.PreparedSQL.NotPrepared
$locations_by_rate = $this->get_locations_by_rate_ids( $results );
$this->output_default_tax_classification_panel( $slug );
?>
|
|
|
|
|
|
|
|
|
tax_rate_id ] ) ? $locations_by_rate[ $result->tax_rate_id ] : array();
$postcode = array();
$city = array();
foreach ( $location_results as $location_result ) {
if ( ! isset( $location_result->location_type ) ) {
continue;
}
switch ( $location_result->location_type ) {
case 'postcode':
$postcode[] = $location_result->location_code;
break;
case 'city':
$city[] = $location_result->location_code;
break;
}
}
$country = empty( $result->tax_rate_country ) ? '*' : $result->tax_rate_country;
$state = empty( $result->tax_rate_state ) ? '*' : $result->tax_rate_state;
$postcode = empty( $postcode ) ? '*' : implode( '; ', $postcode );
$city = empty( $city ) ? '*' : implode( '; ', $city );
$scheme = isset( $edi_tax_settings['rate'][ $result->tax_rate_id ]['scheme'] ) ? $edi_tax_settings['rate'][ $result->tax_rate_id ]['scheme'] : 'default';
$scheme_default = isset( $edi_tax_settings['class'][ $slug ]['scheme'] ) ? $edi_tax_settings['class'][ $slug ]['scheme'] : '';
$scheme_code = ( 'default' === $scheme ) ? $scheme_default : $scheme;
$category = isset( $edi_tax_settings['rate'][ $result->tax_rate_id ]['category'] ) ? $edi_tax_settings['rate'][ $result->tax_rate_id ]['category'] : 'default';
$category_default = isset( $edi_tax_settings['class'][ $slug ]['category'] ) ? $edi_tax_settings['class'][ $slug ]['category'] : '';
$category_code = ( 'default' === $category ) ? $category_default : $category;
$reason = isset( $edi_tax_settings['rate'][ $result->tax_rate_id ]['reason'] ) ? $edi_tax_settings['rate'][ $result->tax_rate_id ]['reason'] : 'default';
$reason_default = isset( $edi_tax_settings['class'][ $slug ]['reason'] ) ? $edi_tax_settings['class'][ $slug ]['reason'] : '';
$reason_code = ( 'default' === $reason ) ? $reason_default : $reason;
echo '';
echo '| ' . esc_html( $country ) . ' | ';
echo '' . esc_html( $state ) . ' | ';
echo '' . esc_html( $postcode ) . ' | ';
echo '' . esc_html( $city ) . ' | ';
echo '' . esc_html( wc_round_tax_total( $result->tax_rate ) ) . '% | ';
echo '';
$this->output_tax_selector_for( 'scheme', 'rate', $result->tax_rate_id, $scheme );
echo ' ' . esc_html__( 'Code', 'woocommerce-pdf-invoices-packing-slips' ) . ': ' . esc_html( $scheme_code ) . ' ';
echo ' | ';
echo '';
$this->output_tax_selector_for( 'category', 'rate', $result->tax_rate_id, $category );
echo ' ' . esc_html__( 'Code', 'woocommerce-pdf-invoices-packing-slips' ) . ': ' . esc_html( $category_code ) . ' ';
echo ' | ';
echo '';
$this->output_tax_selector_for( 'reason', 'rate', $result->tax_rate_id, $reason );
echo ' ' . esc_html__( 'Code', 'woocommerce-pdf-invoices-packing-slips' ) . ': ' . esc_html( $reason_code ) . ' ';
echo ' | ';
echo '';
echo '
';
}
} else {
echo '| ' . esc_html__( 'No taxes found for this class.', 'woocommerce-pdf-invoices-packing-slips' ) . ' |
';
}
?>
Peppol
%s', esc_url( 'https://wpovernight.com/downloads/woocommerce-edocuments-peppol/?utm_medium=plugin&utm_source=ips&utm_campaign=upgrade-tab&utm_content=peppol-network-cross' ), esc_html__( 'Buy now', 'woocommerce-pdf-invoices-packing-slips' ) ); ?>
array(
'name' => true,
'id' => true,
'class' => true,
'style' => true,
'data-current' => true
),
'option' => array(
'value' => true,
'selected' => true,
)
);
$defaults = array(
'default' => __( 'Default', 'woocommerce-pdf-invoices-packing-slips' ),
);
switch ( $for ) {
case 'scheme':
$options = EN16931::get_vat_cat();
break;
case 'category':
$options = EN16931::get_5305();
break;
case 'reason':
$defaults['none'] = __( 'None', 'woocommerce-pdf-invoices-packing-slips' );
$options = EN16931::get_vatex();
break;
default:
$options = array();
}
$select = '';
echo wp_kses( $select, $allowed_html );
}
/**
* Get tax rate locations grouped by tax_rate_id for a given set of tax rate rows.
*
* @param array $results
* @return array
*/
private function get_locations_by_rate_ids( array $results ): array {
global $wpdb;
$locations_by_rate = array();
if ( empty( $results ) ) {
return $locations_by_rate;
}
$rate_ids = array_values(
array_unique(
array_filter(
array_map(
static function ( $row ) {
return isset( $row->tax_rate_id ) ? (int) $row->tax_rate_id : 0;
},
$results
)
)
)
);
if ( empty( $rate_ids ) ) {
return $locations_by_rate;
}
$placeholders = implode( ',', array_fill( 0, count( $rate_ids ), '%d' ) );
$sql = "SELECT tax_rate_id, location_type, location_code
FROM {$wpdb->prefix}woocommerce_tax_rate_locations
WHERE tax_rate_id IN ( {$placeholders} )";
$loc_rows = $wpdb->get_results( // phpcs:ignore WordPress.DB.DirectDatabaseQuery.DirectQuery, WordPress.DB.DirectDatabaseQuery.NoCaching
$wpdb->prepare( $sql, $rate_ids ) // phpcs:ignore WordPress.DB.PreparedSQL.NotPrepared
);
if ( empty( $loc_rows ) ) {
return $locations_by_rate;
}
foreach ( $loc_rows as $loc_row ) {
$id = (int) $loc_row->tax_rate_id;
if ( ! isset( $locations_by_rate[ $id ] ) ) {
$locations_by_rate[ $id ] = array();
}
$locations_by_rate[ $id ][] = $loc_row;
}
return $locations_by_rate;
}
}
endif; // class_exists