The id is not working. It shows as text on the page for some reason.
How is this happening?
I have isolated the sample button. Please see screenshot.
I need faster support. I am not getting fast enough responses here.
Minesh
Supporter
Languages:
English (English )
Timezone:
Asia/Kolkata (GMT+05:30)
Sorry if you feel so but looks like we are in a different timezone.
However, I've checked now and I also checked the rendered HTML output of button and I can see now value attribute for the button is rendered correctly. I've adjusted the code as given under:
function display_display_sample_btn() {
global $post;
$str .='<form class="cart" method="post" enctype="multipart/form-data">';
$str .= '<button type="submit" name="add-to-cart" value="'.$post->ID.'" class="single_add_to_cart_button button alt">Order a Free Sample</button>';
$str .= '<input type="hidden" name="free_sample" value="'.$post->ID.'">';
$str .= '</form>';
return $str;
}
add_shortcode( 'woo_display_sample_btn', 'display_display_sample_btn' );
Thanks but now this is not working. It functions like a regular add to cart button instead.
What I expected:
When click on "Order a Free Sample", it will add "Free Sample (Product Name)".
Instead:
Adds normal product to cart.
Thank you,
Minesh
Supporter
Languages:
English (English )
Timezone:
Asia/Kolkata (GMT+05:30)
Well - I can help you to run the code but I do not know about the free sample and how it works. Do you want me to place to code to the functions.php file as before?
hidden link
Here is the source for the free sample code. I believe since we changed theID() , it no longer is passing the information to the cart.
Minesh
Supporter
Languages:
English (English )
Timezone:
Asia/Kolkata (GMT+05:30)
I think the mistake was we need to replace the sample product ID - in your case the sample product ID is 2689.
I've added the sample product ID accordingly - Can you please check:
function display_display_sample_btn() {
global $post;
$str .='<form class="cart" method="post" enctype="multipart/form-data">';
$str .= '<button type="submit" name="add-to-cart" value="2689" class="single_add_to_cart_button button alt">Order a Free Sample</button>';
$str .= '<input type="hidden" name="free_sample" value="'.$post->ID.'">';
$str .= '</form>';
return $str;
}
add_shortcode( 'woo_display_sample_btn', 'display_display_sample_btn' );
My issue is resolved now. Thank you!