WooCommerce change loading spinner icon
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() {
?>
<style>
.woocommerce .blockUI.blockOverlay:before,
.woocommerce .loader:before {
height: 3em;
width: 3em;
position: absolute;
top: 50%;
left: 50%;
margin-left: -.5em;
margin-top: -.5em;
display: block;
content: "";
-webkit-animation: none;
-moz-animation: none;
animation: none;
background-image:url('<?php echo get_stylesheet_directory_uri() . "/img/my_spinner.gif"; ?>') !important;
background-position: center center;
background-size: cover;
line-height: 1;
text-align: center;
font-size: 2em;
}
</style>
<?php
}
Code goes in function.php file of your active child theme (or active theme). Tested and works.
Starting and stoping Ajax Overlay spinner in Woocommerce
Woocommerce Uses jQuery BlockUI Plugin to make a blocking overlay with an animate spinner on some jQuery events and on specific pages.
Here below is an example on the checkout page, that will activate woocommerce spinners after a delay of 2 seconds once page is loaded and will stop them after 3 seconds:
add_action('wp_footer', 'spinners_example_on_checkout_jquery_script');
function spinners_example_on_checkout_jquery_script() {
if ( is_checkout() && ! is_wc_endpoint_url() ) :
?>
<script type="text/javascript">
jQuery( function($){
// Targeting checkout checkout payment and Review order table like Woocommerce does.
var a = '.woocommerce-checkout-payment, .woocommerce-checkout-review-order-table';
// Starting spinners with a delay of 2 seconds
setTimeout(function() {
// Starting spinners
$(a).block({
message: null,
overlayCSS: {
background: "#fff",
opacity: .6
}
});
console.log('start');
// Stop spinners after 3 seconds
setTimeout(function() {
// Stop spinners
$(a).unblock();
console.log('stop');
}, 5000);
}, 2000);
});
</script>
<?php
endif;
}
Code goes in function.php file of your active child theme (or active theme). Tested and works.
The jQuery BlockUI Plugin official documentation.
Related Topics
What Is the Format for E-Mail Headers That Display a Name Rather Than the E-Mail
Pdo Fetchall Group Key-Value Pairs into Assoc Array
Get the Last Modified Date of a Remote File
Download CSV File Using "Ajax"
PHP - Import CSV File to MySQL Database Using Load Data Infile
How to Check That an Object Is Empty in PHP
Get the First Letter of Each Word in a String
Php: Settings Memory_Limits > 1024M Does Not Work
Should My PHP Functions Accept an Array of Arguments or Should I Explicitly Request Arguments
How to Get Final Url After Following Http Redirections in Pure PHP
Publishing to User's Wall Without Being Online/Logged-In - Facebook Sharing Using Graph API
Is MySQL_Real_Escape_String() Necessary When Using Prepared Statements
Get Text from <Option> Tag Using PHP
Parse Error: Syntax Error, Unexpected '[', Expecting ')'
Remove or Hide "Add New" Button on Woocommerce on Bulk Order Panel