• After switching user, when visiting the checkout, the following error is displayed:
    PHP Fatal error: Uncaught TypeError: trim(): Argument #1 ($string) must be of type string, array given in /nas/content/live/website/wp-includes/formatting.php:445
    It seems that an array is being passed instead of a string to the wc_get_formatted_cart_item_data function which breaks the checkout page.

    This error is only visible when browsing the site after switching users using this plugin.

    Could you please take a look and correct the error?

Viewing 2 replies - 1 through 2 (of 2 total)
  • Plugin Author John Blackbourn

    (@johnbillion)

    WordPress Core Developer

    Thanks for the report @leossah. Are you able to test this with the other plugins on your site deactivated? (Except WooCommerce and User Switching of course). There’s nothing specific in User Switching that affects how WooCommerce works, so it could well be a third party plugin which is causing a problem that only appears under a specific circumstance.

    Failing that, can you let me know:

    • The WooCommerce version number
    • WordPress version number
    • PHP version number
    • List of the active plugins on your site

    I had the same problem without the User Switching plugin. A few customers could not change their subscription (with WooCommerce Subscriptions plugin) from monthly to yearly or manually pay a failed renewal payment without getting a fatal error that caused the site to get blank until cache was completely emptied and browser restarted.

    I paid a programmer on Codeable to fix that problem. He found out the cause was the WooCommerce template cart/cart-item-data.php. He says it causes the ?wc_get_formatted_cart_item_data() function to return an array when it should ideally return a string. This then conflicts with the wpautop() function, which is causing the error.

    This is the working fix for the problem in woocommerce/cart/cart-item-data.php:

    if ( ! defined( 'ABSPATH' ) ) {
    	exit;
    }
    ?>
    <dl class="variation">
    	<?php foreach ( $item_data as $data ) : ?>
    		<dt class="<?php echo sanitize_html_class( 'variation-' . $data['key'] ); ?>"><?php echo wp_kses_post( $data['key'] ); ?>:</dt>
    		<dd class="<?php echo sanitize_html_class( 'variation-' . $data['key'] ); ?>">
                <?php if (is_array($data['display'])) { ?>
                    <?php foreach ($data['display'] as $key => $value) { ?>
                        <?php echo wp_kses_post( wpautop( $value ) ); ?>
                    <?php } ?>
                <?php } else { ?>
                    <?php echo wp_kses_post( wpautop( $data['display'] ) ); ?>
                <?php } ?>
    	<?php endforeach; ?>
    </dl>
    

    I hope you can permanently implement this solution into the template.

Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘Error on the checkout page’ is closed to new replies.