• Resolved Ewout

    (@pomegranate)


    Getting this on orders with meta data with multidimensional arrays:

    
    Notice: Undefined offset: 0 in /wp-content/plugins/woocommerce-store-toolkit/templates/admin/order_data.php on line 21
    

    I think this would work better/be more fail safe:

    
    $inner_meta_value = maybe_unserialize( $inner_meta_value );
    if( is_array( $inner_meta_value ) && count( $inner_meta_value ) == 1 ) {
    	$inner_meta_value = maybe_unserialize( array_shift( $inner_meta_value ) );
    }
    

    Although it also begs the question why it doesn’t show it as an array when it is. I understand this for the top-level meta because pretty much every meta in WP is stored as an array, but for arrays within the meta there is no such convention so I would say it’s better to just display it as a array, and also visually show the extra level with an additional >>, like so:

    
    			<?php foreach( $meta_value as $inner_meta_name => $inner_meta_value ) { ?>
    				<?php
    				$inner_meta_value = maybe_unserialize( $inner_meta_value );
    				?>
    				<?php if( is_array( $inner_meta_value ) ) { ?>
    		<tr>
    			<th colspan="3">&raquo; <?php echo $inner_meta_name; ?></th>
    		</tr>
    					<?php foreach( $inner_meta_value as $inner_meta_name => $inner_meta_value ) { ?>
    		<tr>
    			<th style="width:20%;">&raquo; &raquo; <?php echo $inner_meta_name; ?></th>
    			<td><?php echo ( is_array( $inner_meta_value ) ? print_r( $inner_meta_value, true ) : $inner_meta_value ); ?></td>
    			<td>&nbsp;</td>
    		</tr>
    					<?php } ?>
    
    				<?php } else { ?>
    

    Thanks for a fantastic tool!

    • This topic was modified 5 years, 9 months ago by Ewout. Reason: added some thoughts
Viewing 13 replies - 1 through 13 (of 13 total)
Viewing 13 replies - 1 through 13 (of 13 total)
  • The topic ‘Notices on multidimensional arrays’ is closed to new replies.