Skip to content

Instantly share code, notes, and snippets.

@kayode-adechinan
Created August 4, 2020 16:58
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save kayode-adechinan/edd6f4a660fddb4c29f222f261101a92 to your computer and use it in GitHub Desktop.
Save kayode-adechinan/edd6f4a660fddb4c29f222f261101a92 to your computer and use it in GitHub Desktop.
// The custom replacement button function
function custom_product_button(){
// HERE your custom button text and link
$button_text = __( "WhatSapp", "woocommerce" );
$button_link = "https://web.whatsapp.com/send?phone=+221785421818&text=Votre%20annonce%20publi%C3%A9e%20sur%20AdafriMarket%20m%27int%C3%A9resse.%20https://sn.coinafrique.com/annonce/demandes-demploi/demande-demploi-boy-2512208";
// Display button
echo '<a class="button" target="_blank" href="'.$button_link.'">' . $button_text . '</a>';
}
// Replacing the single product button add to cart by a custom button for a specific product category
add_action( 'woocommerce_single_product_summary', 'replace_single_add_to_cart_button', 1 );
function replace_single_add_to_cart_button() {
global $product;
// Only for product category ID 64
/*if( has_term( '64', 'product_cat', $product->get_id() ) ){
put the code over here
}*/
// For variable product types (keeping attribute select fields)
if( $product->is_type( 'variable' ) ) {
remove_action( 'woocommerce_single_variation', 'woocommerce_single_variation_add_to_cart_button', 20 );
add_action( 'woocommerce_single_variation', 'custom_product_button', 20 );
}
// For all other product types
else {
remove_action( 'woocommerce_single_product_summary', 'woocommerce_template_single_add_to_cart', 30 );
add_action( 'woocommerce_single_product_summary', 'custom_product_button', 30 );
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment