I have been scratching my head on this one for a day now. Various searching through Google, WordPress, and StackOverflow have given me leads, but as I am not anything more than a beginner PHP guy that can only really change some things around, I am completely stumped. I apologize if this error is similar to other questions that have been asked, but I can’t find a solution to my particular issue. I have support tickets with both WordPress and the theme developer, but I haven’t found a solution yet. Here is the isse:
I am having an issue with a website that I am working on for a family member. I was trying to change the size of the product image in WooCommerce, so I made edits to the woocommerce.php file, changing the woocommerce_single_image_width size. After doing that, I get this “Illegal string” error:
Warning: Illegal string offset ‘crop’ in
/home/wp_tnn5rz/funstickups.com/wp-content/themes/bazar-child/theme/woocommerce.php
on line 812Warning: Illegal string offset ‘width’ in
/home/wp_tnn5rz/funstickups.com/wp-content/themes/bazar-child/theme/woocommerce.php
on line 822Warning: Illegal string offset ‘height’ in
/home/wp_tnn5rz/funstickups.com/wp-content/themes/bazar-child/theme/woocommerce.php
on line 823Warning: Illegal string offset ‘crop’ in
/home/wp_tnn5rz/funstickups.com/wp-content/themes/bazar-child/theme/woocommerce.php
on line 824Warning: Illegal string offset ‘width’ in
/home/wp_tnn5rz/funstickups.com/wp-content/themes/bazar-child/theme/woocommerce.php
on line 828Warning: Illegal string offset ‘height’ in
/home/wp_tnn5rz/funstickups.com/wp-content/themes/bazar-child/theme/woocommerce.php
on line 828Warning: Illegal string offset ‘crop’ in
/home/wp_tnn5rz/funstickups.com/wp-content/themes/bazar-child/theme/woocommerce.php
on line 828
After doing some research, I found that this is more of an error, but since I have made the changes, I am unable to upload photos, or view my media in grid view (it works in list view though).
I downloaded the regenerate thumbnails plugin, but it told me that the action had failed. The images are small.. 566×3-something, so I don’t think that it is caused by the size of the image.
In a last ditch effort, I deleted all of the products and decided to try it over, but I can’t upload the images now, so I’m completely stuck.
The url is https://www.funstickups.com
Thanks you in advance!
Angelo
Here is the code from woocommerce.php (lines 803-832) where the errors are coming from.
function yit_get_featured_image_size() {
$element['width'] = "160";
$element['height'] = "160";
$element['crop'] = 1;
$element = get_option( 'shop_featured_image_size', $element );
$crop = WC_Admin_Settings::get_option( 'shop_featured_image_size' . '[crop]' );
$element['crop'] = ( $crop == 'on' || $crop == '1' ) ? 1 : 0;
return $element;
}
function yit_add_featured_image_size($images) {
$element = yit_get_featured_image_size();
if ( ! is_array( $element ) ) {
$element['width'] = "160";
$element['height'] = "160";
$element['crop'] = 1;
}
$image_sizes = array(
'shop_featured_image_size' => array( intval( $element['width'] ), intval( $element['height'] ), ( $element['crop'] === 1 ? true : false ) ),
);
return array_merge( $image_sizes , $images );
}
You’re treating
$element
as though it’s an array without setting it as one first.Change this:
To:
As long as
$element
is an array you can continue to append elements in the way you were originally, e.g.$element['extra'] = ...
.Problem solved. It was an issue with the theme itself and WooCommerce. Thank you for the help!
Never change/hack the woocommerce core.
In my case, all I had to do was resetting my image size settings in the Customizer. Navigate to WooCommerce -> Product Images.
Change the size, save, change the size back to your desired size and save again.