New Landing How can we help? Atelier Product category hero image bug (and fix)

Viewing 5 posts - 1 through 5 (of 5 total)
  • Posted in: Atelier
  • #170739
    Saskia
    Member
    Post count: 20

    I found a bug in the way the product category hero image works.

    In the theme options we find:
    Theme options -> WooCommerce Options -> Shop Options -> WooCommerce Hero Heading Background Image

    Upload a custom image which will show on ALL category pages when the heading style is set to ‘hero’.

    But if we want to show a custom image for a specific category, we can go into:
    Products -> Categories -> Edit Product Category

    Then we can upload a custom image to a specific category which will override the default custom image we set in the theme options.

    So far everything works fine.

    However, if we decide we no longer want the custom image on that specific category, and delete the hero image, it should then default back to the image we specified in the theme options.

    But that’s where it breaks. After you remove the hero image from the product category page, it never goes back to the default image. Instead it just goes completely blank and shows no image.

    After much snooping around with MySQL, I worked out why it’s broken.

    Here is a table i pulled up from the database:

    mysql> select * from wp_woocommerce_termmeta where meta_key="hero_id";
    +---------+---------------------+----------+------------+
    | meta_id | woocommerce_term_id | meta_key | meta_value |
    +---------+---------------------+----------+------------+
    |     695 |                   6 | hero_id  | 3371       |
    |     696 |                  19 | hero_id  | 0          |
    |     697 |                  18 | hero_id  | 0          |
    |     698 |                  54 | hero_id  | 0          |
    +---------+---------------------+----------+------------+
    4 rows in set (0.01 sec)

    Keeping in mind woocommerce_term_id is the product category id. So in the table we have 4 product categories for which I have uploaded a custom hero image.
    The first one has an image with a meta_value = 3371.
    The next three are have had their images deleted, so their meta_value = 0.

    The file which is at fault is ‘sf-page-heading.php’, and the code (at line 100) is as follows:

    if ($hero_id != "") {
                    		$fancy_title_image_url = wp_get_attachment_url($hero_id, 'full');
                    	}

    You see from this code that it checks for ‘hero_id’ and as long as it is not blank, it assumes there is valid data and tries to pull up the corresponding image. So if the meta_value = 0 (which is not blank, but contains ‘0’), it tries to find an image_id = 0, which doesn’t exist.

    I came up with a really simple solution:

    if ($hero_id != "" && $hero_id != "0") {
                    		$fancy_title_image_url = wp_get_attachment_url($hero_id, 'full');
                    	}

    This checks for the existence of hero_id, and checks that it’s not blank, and also checks that it’s not ‘0’ (i.e. deleted). Now it works perfectly, so product category hero images which have been deleted will now default back to the theme uploaded hero image instead of showing a blank.

    Of course, another way would be to delete those hero_id values completely from the database when an image is deleted, but that would probably be a lot more effort than it’s worth.

    #170856
    Rui Guerreiro – SUPPORT
    Keymaster
    Post count: 25779

    Hi,

    Thanks for detailed explanation.

    Will forward to the development so they can analyse the situation.
    -Rui

    #170942
    Swift Ideas – Ed
    Keymaster
    Post count: 15264

    Thanks @Saskia, odd that it is set to 0 instead of removed. I’ve added in the code to check for this, thank you for providing that.

    – Ed

    #194644
    sobepolitics
    Member
    Post count: 7

    How do I create or use one of the existing pages for my archive and categories result pages. My logo and header is not fully appearing on these pages because of the white background. See attachment to see the difference. Thanks in advance.

    Attachments:
    You must be logged in to view attached files.
    #194831
    Rui Guerreiro – SUPPORT
    Keymaster
    Post count: 25779

    Hi,

    This don’t seem related with this topic.
    Can you create a new one and we will assist you there, will need your site url that you can fill in the topic form.

    Thanks

    -Rui

Viewing 5 posts - 1 through 5 (of 5 total)

You must be logged in and have valid license to reply to this topic.

License required for one of the following items
Login and Registration Log in · Register