• Resolved laletizia

    (@laletizia)


    Hello, I’m trying to add a custom field (select type, multiple choice), but I keep receiving the error shown below. The other custom fields are displayed correctly, except for the date which, in the return format, despite being set as d/m/Y, is displayed without spaces.

    Thank you in advance.

    Fatal error: nl2br(): Argument #1 ($string) must be of type string, array given
    /home/customer/www/demo-staging.com/public_html/wp-content/plugins/woocommerce-pdf-invoices-packing-slips/includes/documents/abstract-wcpdf-order-document-methods.php (257)
    #0 /home/customer/www/demo-staging.com/public_html/wp-content/plugins/woocommerce-pdf-invoices-packing-slips/includes/documents/abstract-wcpdf-order-document-methods.php(257): nl2br(Array)
    #1 /home/customer/www/demo-staging.com/public_html/wp-content/themes/helter-child/woocommerce/pdf/Zeno/invoice.php(116): WPO\WC\PDF_Invoices\Documents\Order_Document_Methods->custom_field('dispositivo_med...')
    #2 /home/customer/www/demo-staging.com/public_html/wp-content/plugins/woocommerce-pdf-invoices-packing-slips/includes/documents/abstract-wcpdf-order-document.php(976): include('/home/customer/...')
    #3 /home/customer/www/demo-staging.com/public_html/wp-content/plugins/woocommerce-pdf-invoices-packing-slips/includes/documents/abstract-wcpdf-order-document.php(879): WPO\WC\PDF_Invoices\Documents\Order_Document->render_template('/home/customer/...', Array)
    #4 /home/customer/www/demo-staging.com/public_html/wp-content/plugins/woocommerce-pdf-invoices-packing-slips/includes/documents/abstract-wcpdf-order-document.php(834): WPO\WC\PDF_Invoices\Documents\Order_Document->get_html()
    #5 /home/customer/www/demo-staging.com/public_html/wp-content/plugins/woocommerce-pdf-invoices-packing-slips/includes/documents/abstract-wcpdf-order-document.php(901): WPO\WC\PDF_Invoices\Documents\Order_Document->get_pdf()
    #6 /home/customer/www/demo-staging.com/public_html/wp-content/plugins/woocommerce-pdf-invoices-packing-slips/includes/class-wcpdf-main.php(466): WPO\WC\PDF_Invoices\Documents\Order_Document->output_pdf('inline')
    #7 /home/customer/www/demo-staging.com/public_html/wp-includes/class-wp-hook.php(310): WPO\WC\PDF_Invoices\Main->generate_pdf_ajax('')
    #8 /home/customer/www/demo-staging.com/public_html/wp-includes/class-wp-hook.php(334): WP_Hook->apply_filters('', Array)
    #9 /home/customer/www/demo-staging.com/public_html/wp-includes/plugin.php(517): WP_Hook->do_action(Array)
    #10 /home/customer/www/demo-staging.com/public_html/wp-admin/admin-ajax.php(188): do_action('wp_ajax_generat...')
    #11 {main}

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

    (@alexmigf)

    Hi @laletizia

    Can you show us your custom field settings?

    Thread Starter laletizia

    (@laletizia)

    Hi Alex,

    see below.

    array(
    			'key' => 'field_5da98995e5fc3',
    			'label' => 'Dispositivo Medico zenO',
    			'name' => 'dispositivo_medico',
    			'aria-label' => '',
    			'type' => 'select',
    			'instructions' => '',
    			'required' => 0,
    			'conditional_logic' => 0,
    			'wrapper' => array(
    				'width' => '',
    				'class' => '',
    				'id' => '',
    			),
    			'choices' => array(
    				'XXX è dispositivo medico in classe 1 CE antidecubito' => 'XXX è dispositivo medico in classe 1 CE antidecubito',
    				'XXX è dispositivo medico in classe 1 CE antidecubito' => 'XXX è dispositivo medico in classe 1 CE antidecubito',
    				'XXX è dispositivo medico in classe 1 CE antidecubito' => 'XXX è dispositivo medico in classe 1 CE antidecubito',
    				'XXX è dispositivo medico in classe 1 CE antidecubito' => 'XXX è dispositivo medico in classe 1 CE antidecubito',
    				'XXX è dispositivo medico in classe 1 CE antidecubito' => 'XXX è dispositivo medico in classe 1 CE antidecubito',
    				'XXX è dispositivo medico in classe 1 CE antidecubito' => 'XXX è dispositivo medico in classe 1 CE antidecubito',
    			),
    			'default_value' => array(
    			),
    			'return_format' => 'value',
    			'multiple' => 1,
    			'allow_null' => 1,
    			'ui' => 0,
    			'ajax' => 0,
    			'placeholder' => '',
    		),
    Plugin Contributor alexmigf

    (@alexmigf)

    A screenshot from the custom field settings would be better. You can host it here: https://imgbb.com

    Thread Starter laletizia

    (@laletizia)

    Plugin Contributor alexmigf

    (@alexmigf)

    If you are accepting with “select multiple” the output is an array right? What is the code that you are using to output the custom field?

    Thread Starter laletizia

    (@laletizia)

    Hi Alex,

    I used the code below.
    It’s the same code I use to print the other custom fields on the invoice. By the way, I have another select field (not multiple-choice) that works correctly. I’ve tried both ‘array’ and ‘value’ as the output, but the result is always the same error.

    <?php $this->custom_field('dispositivo_medico'); ?>
    Plugin Contributor alexmigf

    (@alexmigf)

    Thanks!

    Since you could return multiple options, in your opinion how they should look like?

    Thread Starter laletizia

    (@laletizia)

    In the previous version of the templates (before the implementation code changed), it appeared as shown in the attached image. Just a simple text string, nothing special.
    It’s highlighted in red.

    https://ibb.co/6sLXdS0

    Plugin Contributor dwpriv

    (@dwpriv)

    @laletizia

    My colleagues have notified me that this issue is related to the custom_field function itself. We’ve begun to work on a solution for this.

    • This reply was modified 1 year, 1 month ago by dwpriv. Reason: issue reported, and this solution would not work
    Thread Starter laletizia

    (@laletizia)

    This is my old code, maybe that help.

    <?php
    $dispositivomedico = get_field( 'dispositivo_medico', $wpo_wcpdf->export->order->id );
    if( $dispositivomedico ): ?>
    <?php echo implode( '<br /> ', $dispositivomedico ); ?>
    <?php endif; ?>

    Do you have any ideas about the incorrect date return format (set d/m/Y, displayed dmY, without space)?

    Thank you

    Plugin Contributor dwpriv

    (@dwpriv)

    You can try getting the field from the order data as well with this: $this->order->get_meta( 'dispositivo_medico' ) instead of custom_field('dispositivo_medico'); ?>

    Thread Starter laletizia

    (@laletizia)

    Hello, I also tried changing the field by converting it into a checkbox, but I keep receiving the same error. Checking the error type, I deduce that it’s because it can’t perform the line break.

    Plugin Contributor dwpriv

    (@dwpriv)

    The error is related to an array value being passed in instead of a string. We are currently working on a fix for this

    Plugin Contributor dwpriv

    (@dwpriv)

    Just an update that we have fixed this error in our latest release. After you update the plugin you should be fine ??

Viewing 14 replies - 1 through 14 (of 14 total)
  • The topic ‘Error with Advance custom fields’ is closed to new replies.