samedi 28 mai 2016

WooCommerce add data- attribute to view cart button on success message

I've managed to change the html markup of the View Cart button on success message so I could add id="open_cart" to it, but I also want to add a data- attribute such as data-cart="open" to the html output, however only the id is returned.

Any ideas on how to add a data- attribute to it?

function my_add_to_cart_message() {
    if ( get_option( 'woocommerce_cart_redirect_after_add' ) == 'yes' ) :

    $message = sprintf( '%s<a id="open_cart" data-target="open-cart"  href="%s" class="button">%s</a>', __( 'Successfully added to cart.' , 'woocommerce' ), esc_url( get_permalink( woocommerce_get_page_id( 'cart' ) ) ), __( 'View Cart', 'woocommerce' ) );

    return $message;

}
add_filter( 'wc_add_to_cart_message', 'my_add_to_cart_message' );

This is what the function above returns:

<a id="open_cart" href="http://ift.tt/19O1Z3i" class="button wc-forward">Ver carrinho</a>

The data-cart="open" is ignored. Simply annoying.



via Chebli Mohamed

Aucun commentaire:

Enregistrer un commentaire