I need to resize images. I'm creating my own plugin (not theme). Here's what I use:
function myplugintest_custom_image_size_500_x_500() {
add_image_size( 'myplugintest-size-500-500', 500, 500,0 );
}
add_action( 'init', 'myplugintest_custom_image_size_500_x_500' );
Then I need to get a link to the image to display in my custom block (in myplugintest.php).
$image_url = wp_get_attachment_image_url($product->get_image_id(), 'myplugintest-size-500-500', false);
But I get the original image with the scaled suffix.
This works if I use already registered sizes, for example:
$image_url = wp_get_attachment_image_url($product->get_image_id(), 'woocommerce_single', false);
What could be the problem and how do I register my size?
Upd 1:
If you dive deeper wp_get_attachment_image_url into the function, you can find wp_get_attachment_metadata, which returns $meta. In $meta there is an array sizes which contains all registered sizes, but my size is not there.