There are a few to do this:
Using double quotes
Don’t forget to escape the double quotes inside the string.
global $post;
echo do_shortcode("[sc name=\"$post->post_name\"]");
Using sigle quotes
global $post;
echo do_shortcode("[sc name="$post->post_name"]");
Using sprintf
global $post;
echo do_shortcode(
sprintf('[sc name="%s"]', $post->post_name)
);
Using wp_sprintf
global $post;
echo do_shortcode(
wp_sprintf('[sc name="%s"]', $post->post_name)
);
Using heredoc
do_shortcode(
<<< EOF
[add_to_cart_url id="$post->post_name"]
EOF
);
Related Posts:
- Display sorting options dropdown when using WooCommerce product category shortcode
- Listing and displaying WooCommerce Shipping Zones in the frontend? [closed]
- How to work Woocommerce pagination inside shortcode?
- How to get woocommerce orders with get_posts method in a shortcode
- How to add a shortcode which runs a .php file for the current post
- Add Shortcode to ::before class
- How call WordPress shortcode inside function file
- How to add date range in woocommerce with code
- Shortcode putting html such as
- WooCommerce: How to display item meta data in email confirmation using woocommerce_order_item_meta_end
- How to get the original price of the product in woocommerce?
- How to Remove a Filter from the Admin List Table?
- Woocommerce, recognize the loop of related products
- Remove commas from WooCommerce checkout addresses fields
- My shortcode is showing up twice
- WooCommerce Link to Product Category
- Output a WooCommerce product custom field in WooCommerce using get_post_meta()
- Append a term to WooCommerce product existing product category terms
- How to find the output of contact form 7 shortcode? [closed]
- How do i get (unique) page name?
- using woocommerce_template_single_add_to_cart in shop-loop – javascript issues [closed]
- Can A Shortcode Get HTML/Text From Content And Return It Twice With Added HTML?
- Browser title script ignoring is_page /else conditional [closed]
- How to limit the content coming from wordpress shortcodes?
- Writing scripts using WordPress / WooCommerce classes?
- How to make custom total price reactive in navigation
- Change description on specific WooCommerce product status change
- Woocommerce – Filter Variable Products by Variation Attributes and Variations Regular Price
- How to add a second ‘place order’ button in WooCommerce [closed]
- Woocommerce redirect thankyou page based on product ID doesn’t empty Cart
- tracking number field in Woocommerce order [closed]
- WooCommerce Related Products by Attribute
- Image as Sales Badge
- How to display data from custom table in wordpress phpmyadmin
- Modify HTML structure of fields in woocommerce checkout form
- Trying to place a custom field after the total section in the checkout page in woocommerce
- WordPress default Search function inconsistent in WooCommerce Product Titles
- Creating own shortcode – echoeing php variable based on JS variable
- Trouble checking if custom woocommerce checkout field is empty or not
- My new button is in the wrong place
- Only first shortcode gets executed
- displaying content that includes shortcodes within an echo
- Extend Woocommerce Widget Class – WC_Widget_Product_Categories
- Capitalize Shortcode Value on Output
- Why is my str_replace not working on short code submitted by front-end?
- Shortcode not staying inside div tag
- Include js script ONLY on woocommerce product category pages? [closed]
- WP_Query multiple post results
- Convert Featured products loop into Recent products loop?
- Shortcode function doesnt work without caption
- Woocommerce order status payment
- Dynamically added custom fields not displayed on WooCommerce email notifications
- Payment field disappears on custom Paypal plugin
- Creating a brand attribute as a variable
- How do I set a hidden field to a value?
- Display logged in user name and lastname on page
- I am having errors with checkout on wordpress
- Replace background image with post thumbnail in shortcode
- Programmatically add a product to the cart and set price to zero when buying from certain category
- I want to show cart items number if any or nothing, simple CART text
- How to retrieve quantity input field by id in woocommerce
- Conditional formatting on data fetched from MYSQL
- Get only relevant sub-category of category “Genre” that applies to current product only
- Having trouble creating two shortcodes, one for logged in user and one for visitors
- Using zip code to display custom data in Admin Order Details
- How can I update the price when someone enters postcode or zip code in woocommerce checkout page?
- Including user data in “new user notification email”
- How do I remove an action hook inside a class that is called by another class?
- Display current user metadata on WordPress page
- Reload page with a different shortcode when a user selects from a dropdown
- i want add conditional for add category in wordpress
- WooCommerce get products based on the taxonomy
- Woocommerce Add custom “Add to cart button” in single page with tags
- Shortcode’s output to use as other shortcode’s parameter
- append data to mysql table via submit button coded in php – not working
- random woocommerce categories are not showing when count enabled?
- PHP – Woocommerce 3.2 Add variable shipping insurance with multiple “else if ” conditions
- how to display woocomerce description of each category in wordpress? [closed]
- WordPress 3.0 PHP Error – notice WordPress_product_Type was called incorrectly
- Add two or multiple functions in WordPress Post or Page
- Shortcode Works for Logged in Users but Not Working for Guest
- WooCommerce – Add product category below product price [closed]
- perform mathematical operation on shortcode
- Update same content in multiple posts at once?
- Adding my own custom template page but got white page
- problem multisite with blog id
- Create dynamic content from one WP page to multiple other pages
- Shortcode Display From WordPress Dashboard Page Without Using post_id
- Do_shortcode on PHP file outside theme ALMOST works
- Custom Shortcode with Dynamic Button
- wc_add_notice not working on cart page
- ACF | WooCommerce | Theme Development | How to include a /template-part/ that makes use of ACF’s on a custom WooCommerce homepage?
- Woocommerce – Shipping tax class based on cart items not using the highest tax available
- How do I update product shipping using PHP in WooCommerce?
- How can I edit the WooCommerce Mini DropDown Cart to read as follows
- Shortcode for Visual Composer Grid fails turning string to integer
- Grabbing value of input field inside of array
- How to set variable to specific field when querying
- WooCommerce Checkout Cart [closed]
- Woocommerce – add tracking code to another email template