Why are my product images not showing in checkout?

Hi

I don't have any of my product images showing in the shopping cart like they used too. Is this already a well known bug? I'm using it with Appointments +

Kind Regards
Kieran

  • Kieran
    • The Crimson Coder

    Hi Vaughan

    I've tried this quickly on my test site and it's still not working unfortunately.

    It seems to create a variation every time I make a booking and there's no product image in my cart

    Would appreciate any help you can offer

    Regards
    Kieran

  • Sajid
    • DEV MAN’s Sidekick

    Hi @Kieran

    Its Sajid, working alongside Vaughan here :slight_smile:

    I am sorry for delay on this ticket. I can see you are using MarketPress version 3.0.0.3 where as we are just released version 3.0.0.6.

    Please update to latest verison and let us know if its still not working for you.

    Take care and have a nice day :slight_smile:

    Cheers, Sajid

  • Vaughan
    • Support/SLS MockingJay

    Hi Kieran,

    You do actually mean the featured image for the appointment product? It's not currently possible to attach a featured image to the appointment, but i'll have a look into this. Is the below screenshot what you are referring to?Just soI know we're talking about the same thing.

    Thanks

  • Vaughan
    • Support/SLS MockingJay

    Hi Kieran,

    We can use a custom function for this.

    Firstly,

    #1 Create a file called app_mp_cart_thumbnail.php

    #2 Add the following code to this file;

    <?php
    /* Adds a specified image for each service to appointments productsin cart */
    add_filter( 'mp_default_product_img', 'app_thumb_for_mp_product', 999 );
    function app_thumb_for_mp_product() {
        $cart = $cart = MP_Cart::get_instance();
        $items = $cart->get_items();
        $uploads = wp_upload_dir();
        $default = mp_plugin_url( 'ui/images/default-product.png' );
    	foreach ($items as $variation => $amount) {
    		$app_id = MP_Product::get_variation_meta($variation, 'name');
            $app = appointments_get_appointment($app_id);
            if($app) {
                switch($app->service) {
                    default:
                        $img_url = $default;
                        break;
    
                    case 1:
                        $img_url = 'URL_FOR_SERVICE_ID_IMAGE_TO_USE';
                        break;
    
                    case 2:
                        $img_url = 'URL_FOR_SERVICE_ID_IMAGE_TO_USE';
                        break;
                }
            }
    	}
    
        return (isset($img_url) ? esc_url($img_url) : $default);
    }

    Save.

    #3 Now using FTP

    Each case in the function represents the service_id of the service booked which you can find in the services admin page.

    Dashboard > appointments > settings > services

    Then for each service_id you need to create a case in the above function & use the name for eachimage

    Enter the URL for each image you want to use for each service_id in the line that reads

    URL_FOR_SERVICE_ID_IMAGE_TO_USE

    So it looks like;

    case 1:
                        $img_url = 'http://path/to/your/image/file.png';
                        break;
    
                    case 2:
                        $img_url =  'http://path/to/your/image/file2.png';
                        break;

    You need to create a case like above for each service id, you can get the URL from your media managaer.

    The above is assuming you have 2 services with ID's 1 & 2.

    Now upload this file to /wp-content/mu-plugins

    If mu-plugins doesn't exist, create it.

    Now you should see an image displayed for each apps+ product in the cart.

    Hope this helps

  • Vaughan
    • Support/SLS MockingJay

    Hi,

    Ignore the above code. it doesn't work correctly.

    I have managed to get it working, but it requires a core edit in appointments+ plugin.

    i've attached the edited file here.

    Unzip the attached zipfile.

    Now using FTP.

    Upload the enclosed file

    class_app_mp_bridge.php

    upload this to the following location using FTP:

    /wp-content/plugins/appointments/includes/

    Be sure to overwrite the existing file.

    Once done.

    You need to create a mu-plugin.

    create a file called app_custom_mp_image.php

    Add the following code to this file;

    <?php
    /* Adds a specified image for each service to appointments productsin cart */
    add_filter( 'app_service_img_thumbnail', 'app_thumb_for_mp_product', 999, 2 );
    function app_thumb_for_mp_product($thumbnail_id, $service) {
            switch($service) {
                case 1:
                    $thumbnail_id = 979;
                    break;
    
                case 2:
                    $thumbnail_id = 527;
                    break;
            }
    
        return isset($thumbnail_id) ? (int) $thumbnail_id : false;
    }

    You need to create a case for each service_id (inexample above there are 2 cases. case 1 = service_id 1

    You need to add the image id that you wish to use for that service.

    Upload your image to media library (if not already)

    To find the thumbnail_id.

    Click on the image you want to use in your media library

    Dashboard > media > library

    Now look at the URL for the image. it will look something like;

    http://domain.co.uk/wp-admin/post.php?post=979&action=edit

    the 979 in the URL is the thumbnail_id we will use, as you can see in the above example, i entered 979 in the case for that service_id.

    Please be aware, this will be overwritten when apps+ is next updated, however I will try to get this filter added to apps+ before the next release.

    Hope this helps

  • Kieran
    • The Crimson Coder

    Hi Vaughan

    Thanks for the reply. It's nearly working. I can see the product image through the check out pages. It only seems to work as a png file not jpg but that's ok. Maybe I mistyped the number first time?

    However after I have made a booking and I have been redirected to the order status page it doesnt show an image there. Screen shot attached

    Thanks for the help so far though it's nearly there :slight_smile: Be great to get this working in the next upgrade.

    Kind Regards
    Kieran

  • Vaughan
    • Support/SLS MockingJay

    Hi Kieran,

    This has been making my hair go grey trying to figure out, there's a seperate filter in mp_products for image_url, I was trying to use that but had no luck.

    So I looked into how apps +creates the apps variations.

    After extensive hair pulling thinking something In my code is wrong,it turns out this is an actual bug in MP3

    It turns out, products with variations will not have the image displayed on the order-status page.

    Normal products with no variations, seem to work ok.

    I have reported this as a bug to the developer, hopefully we can get this fixed.

    Apologies for the inconvenience.

  • Vaughan
    • Support/SLS MockingJay

    Hi Kieran,

    I'm afraid at the moment, I can only add this to our feature requests list. I've been looking into this and it will require a few changes in the marketpress plugin to be able to make apps+ work with image variations.

    With regards to the previous bug though for normal product variation images, this should be now working in the latest release.

    Thanks

  • Kieran
    • The Crimson Coder

    Hi Vaughan

    The code you gave me has unfortunately stopped working. The only thing I can think of is I've upgraded to Appointments 1.91. I've also ran WP-Smush but the Image ID numbers are the same

    Is there any chance you can take another look at this?

    Kind Regards
    Kieran

  • Kieran
    • The Crimson Coder

    Hi Vaughan

    Thanks for the speedy response. I can see this is now working again. I forgot to replace the Class_app_mp_bridge file upon upgrading the plugin. Sorry my mistake.

    I noted down the edits you did last time. I can see the attached file has them again execpt On line 109 after

    do_action('app_mp_order_paid', $aid, $order);

    you added add this line in the previous version
    if ($do_send) $this->_core->send_confirmation($aid);

    I'm guessing this isn't needed anymore? Is that correct or does it still need added to the attached file. It seems to be working now but be useful just to double check :slight_smile:

    thankyou!

    Kind Regards
    Kieran

  • Vaughan
    • Support/SLS MockingJay

    Hi,

    I'm not entirely sure why I added that line, I don't recall adding it previously, but it's safe to leave it out as it wasn't in the original file. That line of code just sends a confirmation email by the looks of it, and shouldn't affect the image hack.

    Hope this helps

  • Kieran
    • The Crimson Coder

    Hi Vaughan

    This explains why my system was sending two confirmation emails out! I've taken out that adjustment and I'm back to 1 confirmation email and images working! Great I'll head over to my other thread and mark that as resolved too.

    Kind Regards
    Kieran

  • Vaughan
    • Support/SLS MockingJay

    Hi Kieran,

    It looks like the developers added a filter. So there's no need to change that bridge core file in apps+ any longer I don't think.

    But you need to make a small edit to the

    /mu-plugins/add_custom_mp.php file you created.

    find the following:

    add_filter( 'app_service_img_thumbnail', 'app_thumb_for_mp_product', 999, 2 );

    replace with:

    add_filter( 'app_variation_thumbnail', 'app_thumb_for_mp_product', 999, 2 );

    That should hopefully sort it.

  • Vaughan
    • Support/SLS MockingJay

    I've added as a feature request & created a Pull request for the developer to consider.

    Basically, i've modified the mp bridge file, so that it will use the featured image that is set for the Service page description (defined in the Services Options)

    This means, if you setup a services page, and select that page in the Services options, you can add a featured image to that page, this featured image thumbnail will then be used in the MP product.

    Hopefully, it will be included in a future update. But I can't make any guarantees.

  • Kieran
    • The Crimson Coder

    Hi Vaughan

    Does that mean you could set up various pages and then have various images for different services in the same way I have it working now? Sounds good

    It would be nice if you could just chose an image from a seperate drop down menu but if it works it's a start and sounds a nice addition to have.

    Kind Regards
    Kieran

  • Vaughan
    • Support/SLS MockingJay

    Yes, you can select a different page for each service in the Appointments services options.

    So each service will have it's own page, and each page can obviously have it's own featured image.

    It's the easiest way of doing it. Even if you don't use/display the actual pages on your site at all, you can use them just for creating the images for each service regardless.

  • Vaughan
    • Support/SLS MockingJay

    Was just thinking.

    We could actually do that right now using the mu-plugin code.

    This should do it:

    add_filter( 'app_variation_thumbnail', 'app_thumb_for_mp_product', 999, 2 );
    function app_thumb_for_mp_product($thumbnail_id, $service) {
        global $wpdb;
    
        if(!$service) {
            return false;
        }
    
        $thumbnail_id = false;
        $page_id = $wpdb->get_var("SELECT 'page' from $wpdb->prefix . 'app_services' WHERE ID = $service");
    
        if($page_id) {
            $thumbnail_id = (isset(get_post_thumbnail_id($page_id)) ? get_post_thumbnail_id($page_id) : false);
        }
    
        return $thumbnail_id;
    }
  • Kieran
    • The Crimson Coder

    Hi Vaughan,

    Sorry for the long delay on this thread! I've just tried to implement the above code on my new site but get a white screen whenever I try to add the old muplugin (working on my original site)

    I get a white screen when I try you above code too

    I've opened up support on my new site (TreatMeHere) if you get chance I'd be grateful for a quick look. I think I might need the modified mp_bridge code?

    Kind Regards
    Kieran

  • Kieran
    • The Crimson Coder

    Hi Kasia

    I've enabled debug and there is an error on line 14 which is

    $thumbnail_id = (isset(get_post_thumbnail_id($page_id)) ? get_post_thumbnail_id($page_id) : false);

    Error states

    Fatal error: Cannot use isset() on the result of an expression (you can use "null !== expression" instead) in ................/mu-plugins/01_app_custom_mp_image.php on line 14

Thank NAME, for their help.

Let NAME know exactly why they deserved these points.

Gift a custom amount of points.