Home / Archive / MemberPress: Changes Product Image on the Checkout Page
Duplicate Snippet

Embed Snippet on Your Site

MemberPress: Changes Product Image on the Checkout Page

This code snippet changes the product image on the checkout page in MemberPress. By default, MemberPress uses the product image set in the product settings. This snippet allows you to replace that image with a new one of your choice.

Replace NEW-IMAGE-URL-HERE with the URL of the new image you want to display.

Code Preview
php
<?php
function mepr_custom_checkout_image() { ?>
<script>
(function($) {
  if (typeof $ === 'undefined') {
    return; // Safely exit if jQuery isn't available
  }
  function changeCheckoutImage() {
    try {
      $(".mp-table > tbody:nth-child(1) > tr:nth-child(1) > td:nth-child(1) > img:nth-child(1)").attr("src","NEW-IMAGE-URL-HERE");
    } catch(e) {
      console.log('MemberPress checkout image update failed:', e);
    }
  }
  $(document).ready(function() {
    changeCheckoutImage();
    $(document).ajaxComplete(function() {
      changeCheckoutImage();
    });
    $('select[name="billing_country"]').change(function() {
      changeCheckoutImage();
    });
  });
})(jQuery); // Use 'jQuery' instead of '$' to avoid conflicts
</script>
<?php }
// Ensure this runs after jQuery is loaded
add_action('wp_footer', 'mepr_custom_checkout_image', 100);

Comments

Add a Comment