Skip to content

Instantly share code, notes, and snippets.

@tradesouthwest
Last active September 20, 2021 05:28
Show Gist options
  • Save tradesouthwest/d1f136a8c7b5d97451b78114f24009f6 to your computer and use it in GitHub Desktop.
Save tradesouthwest/d1f136a8c7b5d97451b78114f24009f6 to your computer and use it in GitHub Desktop.
Script to add ADA compliant links WordPress Woocommerce + change Checkout message text
/**
* Script to add ADA compliant links
* .woocommerce-store-notice__dismiss-link andd all buttons, some with icons class
* @uses wp_footer()
*/
function ibsen_child_hook_javascript_footer()
{
?>
<script id="isben-add-ntccnt" type="text/javascript">
jQuery(document).ready(function($){
'use strict';
$('a[href^="#"].woocommerce-store-notice__dismiss-link').each(function(){
var oldUrl = $(this).attr("href"); // Get current url
var newUrl = oldUrl.replace("#", "#0"); // Create new url
$(this).attr("href", newUrl); // Set herf value
});
$('.checkout-button, button, .icons').attr('title', text());
})(jQuery);
</script>
<?php
}
add_action( 'wp_footer', 'ibsen_child_hook_javascript_footer', 5 );
/**
* Change Added to cart message.
*/
function codeable_add_to_cart_message_html( $message, $products ) {
$count = 0;
$titles = array();
foreach ( $products as $product_id => $qty ) {
$titles[] = ( $qty > 1 ? absint( $qty ) . ' &times; ' : '' )
. sprintf( _x( '&ldquo;%s&rdquo;', 'x', 'woocommerce' ),
strip_tags( get_the_title( $product_id ) ) );
$count += $qty;
}
$titles = array_filter( $titles );
$added_text = sprintf( _n(
'%s Ticket has been added to cart.', // Singular
'%s Tickets added to cart.', // Plural
$count, // Number of products added
'woocommerce' // Textdomain
), wc_format_list_of_items( $titles ) );
$message = sprintf( '<a href="%s" class="button wc-forward">%s</a> %s',
esc_url( wc_get_checkout_url() ),
esc_html__( 'Go to checkout', 'woocommerce' ),
esc_html( $added_text )
);
return $message;
}
add_filter( 'wc_add_to_cart_message_html', 'codeable_add_to_cart_message_html', 10, 2 );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment