Reputation: 81
I am trying to add content next to add to cart button in woocommerce for specific product, I have used the bellow woocommerce hook, But unfortunately it didn't work:
add_action( 'woocommerce_after_add_to_cart_button', 'add_content_after_addtocart_button_func' );
function add_content_after_addtocart_button_func() {
$current_product = $product->id;
if($current_product === '13333') {
echo '<div class="second_content">Place your content here!</div>';
}
}
Any one can help me on this?
Thanks
Upvotes: 1
Views: 1136
Reputation: 253901
Update: Added compatibility with WC +3
This custom function hooked in woocommerce_single_product_summary
action hook, will display a custom content after add-to-cart
button for a specific product ID
in the single product page:
add_action( 'woocommerce_single_product_summary', 'add_content_after_addtocart_button_func', 35 );
function add_content_after_addtocart_button_func() {
global $product;
// Added compatibility with WC +3
$product_id = method_exists( $product, 'get_id' ) ? $product->get_id() : $product->id;
if($product_id == 13333)
echo '<div class="custom-content">'.__('Place your content here!','woocommerce').'</div>';
}
The Code goes in function.php file of your active child theme (or theme) or also in any plugin file.
This code is tested and works.
Upvotes: 2