Skip to content

Instantly share code, notes, and snippets.

@acanza
Last active April 30, 2024 03:28
Show Gist options
  • Save acanza/9e68706c2967e09df0ff11dfe8fad8c9 to your computer and use it in GitHub Desktop.
Save acanza/9e68706c2967e09df0ff11dfe8fad8c9 to your computer and use it in GitHub Desktop.
[WhatsApp WordPress] Añade CTA flotante para activar conversación
// [WhatsApp] Añade CTA flotante para activar conversación
if ( in_array( 'woocommerce/woocommerce.php', get_option( 'active_plugins' ) ) && version_compare( WC()->version , '3.0.0', '>' ) ){
add_action( 'wp_head', 'include_fontawsome_brands_icons' );
function include_fontawsome_brands_icons(){
?>
<link rel="stylesheet" href="https://use.fontawesome.com/releases/v5.7.2/css/brands.css" integrity="sha384-BKw0P+CQz9xmby+uplDwp82Py8x1xtYPK3ORn/ZSoe6Dk3ETP59WCDnX+fI1XCKK" crossorigin="anonymous">
<?php
}
add_action( 'wp_footer', 'add_whatsapp_sticky_cta' );
function add_whatsapp_sticky_cta(){
//Reemplaza el texto de ejemplo que hay entre comillas, por tu enlace de WhatsApp. ¡Siempre entre las comillas!
$whatsapp_link = "https://api.whatsapp.com/send?phone=34699999999&text=Esto%20es%20un%20mensaje%20de%20prueba";
//Esto evita que el CTA se muestre en páginas "no interesantes" de WooCommerce
if ( !is_checkout() && !is_cart() && !is_account_page() ) {
?>
<a href="<?php echo $whatsapp_link; ?>" rel="nofollow" target="_blank" style="font-size:60px;color:#22BF4A;position:fixed;bottom:20px;right:28px;z-index:999;">
<i class="fab fa-whatsapp" style="background-color: #fff;padding: 10px 14px;border-radius: 50px;"></i>
</a>
<?php
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment