//add button
add_action( 'woocommerce_single_product_summary', 'my_extra_button_on_product_page', 30 );
function my_extra_button_on_product_page() {
global $product;
$product_title = $product->get_name();
$product_price = $product->get_price();
$product_title_html = urlencode($product_title);
echo '<a href="https://api.whatsapp.com/send?phone=60123155968&text='.$product_title_html.'"><img src="https://keladitikusasli.com/wp-content/uploads/2020/04/whatsapp-button.png" width="250"></img></a>';
}
//add button loop
add_action('woocommerce_after_shop_loop_item_title', 'add_a_custom_button', 20);
function add_a_custom_button() {
global $product;
$product_title = $product->get_name();
$product_price = $product->get_price();
$product_title_html = urlencode($product_title);
echo '<a href="https://api.whatsapp.com/send?phone=60123155968&text='.$product_title_html.'"><img src="https://keladitikusasli.com/wp-content/uploads/2020/04/whatsapp-button.png" width="250"></img></a>';
}
Leave a reply