Shortcode Class
Last updated
Was this helpful?
Last updated
Was this helpful?
To create a custom shortcode in WooCommerce with YayMail, you’ll need to use the BaseShortcode class provided by YayMail as a starting point. Here’s a clear example to help you set up your own custom shortcode class
Extending BaseShortcode
:
Begin by defining a new class that extends the BaseShortcode
class provided by YayMail. Make sure to include essential variables and methods needed for the custom shortcode to work properly.
get_shortcodes
The get_shortcodes
function creates a list of shortcodes. Each shortcode follows this structure:
When setting up a shortcode, include these key fields:
Name: A unique identifier for the shortcode.
Description: A short explanation of what the shortcode does.
Group: A category to organize related shortcodes together.
Callback: The function that generates the shortcode’s output.
Attributes (optional): Custom properties, like text_link or color, to enhance the shortcode’s functionality.
Callback function for a shortcode
This function fetches content for displaying shortcodes in the YayMail Editor and in actual emails. It uses two parameters: data and shortcode_atts (for shortcodes with attributes, if applicable).
Variables:
data
: Contains key properties like render_data, template, and is_placeholder.
shortcode_atts
: An array of attributes defined for the shortcode in the get_shortcodes
function.
render_data
: Holds important details, such as order, is_sample, and is_customized_preview in the YayMail Editor. It also includes data from the get_content_html
function when an actual email is sent.
is_placeholder
: (Boolean) Indicates whether the value should be treated as a placeholder. Returns true if it is a placeholder, false otherwise.
is_sample
: (Boolean) Returns true when a sample order is selected in the YayMail Editor, false otherwise.
is_customized_preview
: (Boolean) Returns true when sending a test email or previewing an email in the YayMail Editor, false otherwise.
We’ve followed the steps provided, and the file now correctly includes the use YayMail\Abstracts\BaseShortcode statement.