How to add a product sample button using shortcode on a custom product page in WooCommerce
You can display the sample button on a product page with the [dsfps_sample_button] shortcode.
This is useful when you use a custom product template built with a page builder such as Elementor, Beaver Builder, or WPBakery, and you need to place the button yourself.
In The Article
How to add the sample button shortcode
The shortcode works with custom product templates and lets you place the sample button anywhere on the page.
- Open your product page template in your page builder (for example, Elementor, Beaver Builder, or WPBakery).
- Add a shortcode widget or shortcode block in the place where the button should appear.
- Enter this shortcode:
[dsfps_sample_button] - Update or publish the page, then check the product page on the storefront.
Pro Tips
- Enter the shortcode exactly as
[dsfps_sample_button]. - The product still needs samples enabled, for example in Sample Specific or with Enable sample on the product, or the button may not appear.
- Place the shortcode near Add to cart if you want the sample button in the usual product-action area, or elsewhere if your custom layout needs a different position.
Common Use Cases
Here are some popular ways to use the shortcode:
1. Place the button below the product description
Add the shortcode block under the description in a custom product template.
2. Show the sample option near Add to cart
Add the shortcode next to the Add to cart block in your page builder layout.
3. Use a custom product layout
Place the shortcode in a custom template when the default plugin button position does not fit your design.
FAQs
1. What shortcode do I use?
Use [dsfps_sample_button] in a shortcode widget or shortcode block.
2. Which page builders can I use this with?
The shortcode is useful with custom product templates built with page builders such as Elementor, Beaver Builder, or WPBakery.
3. Why is the button missing after I add the shortcode?
Confirm that the shortcode is entered correctly, that the template is published, and that samples are enabled for that product.