I am trying to change the WooCommerce loading spinner icon. It’s defined in the woocommerce.css:
.woocommerce .blockUI.blockOverlay::before { height: 1em; width: 1em; display: block; position: absolute; top: 50%; left: 50%; margin-left: -.5em; margin-top: -.5em; content: ''; -webkit-animation: spin 1s ease-in-out infinite; animation: spin 1s ease-in-out infinite; background: url(../images/icons/loader.svg) center center; background-size: cover; line-height: 1; text-align: center; font-size: 2em; color: rgba(0,0,0,.75); }
I’ve tried changing the loader.svg with a custom css:
.woocommerce .blockUI.blockOverlay::before { background: url(https://www.localhost.de/wp-content/uploads/custom-loader.svg) center center !important; }
But the icon will not change. So I’ve googled a bit and found this here:
add_filter( 'woocommerce_ajax_loader_url', 'custom_loader_icon', 10, 1 ); function custom_loader_icon() { return __( get_home_path() . 'wp-content/uploads/custom-loader.svg', 'woocommerce' ); }
Best Answer
The following code css rules work in Woocommerce last version. I have embedded them in the wp_head
hook as it’s easy for testing:
You will use this icon for testing, that you will put in your active child theme under an “img
” directory, renaming the file my_spinner.gif
.
If you use a theme instead of a child theme, you will use get_template_directory_uri()
function instead of get_stylesheet_directory_uri()
in the code.
The code:
add_action('wp_head', 'custom_ajax_spinner', 1000 ); function custom_ajax_spinner() { ?> <img src="data:image/gif;base64,R0lGODlhAQABAIAAAAAAAP///yH5BAEAAAAALAAAAAABAAEAAAIBRAA7" data-wp-preserve="%3Cstyle%3E%0A%20%20%20%20.woocommerce%20.blockUI.blockOverlay%3Abefore%2C%0A%20%20%20%20.woocommerce%20.loader%3Abefore%20%7B%0A%20%20%20%20%20%20%20%20height%3A%203em%3B%0A%20%20%20%20%20%20%20%20width%3A%203em%3B%0A%20%20%20%20%20%20%20%20position%3A%20absolute%3B%0A%20%20%20%20%20%20%20%20top%3A%2050%25%3B%0A%20%20%20%20%20%20%20%20left%3A%2050%25%3B%0A%20%20%20%20%20%20%20%20margin-left%3A%20-.5em%3B%0A%20%20%20%20%20%20%20%20margin-top%3A%20-.5em%3B%0A%20%20%20%20%20%20%20%20display%3A%20block%3B%0A%20%20%20%20%20%20%20%20content%3A%20%22%22%3B%0A%20%20%20%20%20%20%20%20-webkit-animation%3A%20none%3B%0A%20%20%20%20%20%20%20%20-moz-animation%3A%20none%3B%0A%20%20%20%20%20%20%20%20animation%3A%20none%3B%0A%20%20%20%20%20%20%20%20background-image%3Aurl('%3C%3Fphp%20echo%20get_stylesheet_directory_uri()%20.%20%22%2Fimg%2Fmy_spinner.gif%22%3B%20%3F%3E')%20!important%3B%0A%20%20%20%20%20%20%20%20background-position%3A%20center%20center%3B%0A%20%20%20%20%20%20%20%20background-size%3A%20cover%3B%0A%20%20%20%20%20%20%20%20line-height%3A%201%3B%0A%20%20%20%20%20%20%20%20text-align%3A%20center%3B%0A%20%20%20%20%20%20%20%20font-size%3A%202em%3B%0A%20%20%20%20%7D%0A%20%20%20%20%3C%2Fstyle%3E" data-mce-resize="false" data-mce-placeholder="1" class="mce-object" width="20" height="20" alt="<style>" title="<style>" /> <?php }
Code goes in function.php file of your active child theme (or active theme). Tested and works.