Your plugin can show extra buttons under the Buy now or Add to cart button of a store item. For example: Live preview, Docs or Support. Each item can have its own links, or no buttons at all.
The buttons show on the item details page and in the item details modal.
Step 1: Save the links with the item
Add a field for each link to the item form. Name the fields plugin_data[your_plugin][key]. RISE saves them with the item. See the article "Add your own data to store items from a plugin - Item fields, buyer inputs and order item values" for more details.
app_hooks()->add_action('app_hook_item_modal_form_store_options', function ($item_info) {
$links = \App\Libraries\Store_manager::get_plugin_data($item_info, "demo_links");
$fields = array("preview_url" => "Live preview URL", "docs_url" => "Docs URL", "support_url" => "Support URL");
foreach ($fields as $key => $label) {
echo '';
echo '';
echo '<input type="text" name="plugin_data[demo_links][' . $key . ']" value="' . esc(get_array_value($links, $key)) . '" class="form-control" />';
echo '';
}
});
Step 2: Show the buttons
Use the app_filter_store_item_details_buttons filter. Add one array for each button and return the list.
app_hooks()->add_filter('app_filter_store_item_details_buttons', function ($buttons, $args) {
$links = get_array_value($args["plugin_data"], "demo_links");
if (!$links) {
return $buttons;
}
if (get_array_value($links, "preview_url")) {
$buttons[] = array("title" => "Live preview", "url" => $links["preview_url"], "icon" => "eye", "sort" => 10);
}
if (get_array_value($links, "docs_url")) {
$buttons[] = array("title" => "Docs", "url" => $links["docs_url"], "icon" => "book-open", "sort" => 20);
}
if (get_array_value($links, "support_url")) {
$buttons[] = array("title" => "Support", "url" => $links["support_url"], "icon" => "life-buoy", "full_width" => true, "sort" => 30);
}
return $buttons;
}, 10, 2);
The second value ($args) has:
| Key | Value |
| item_id | The ID of the item. |
| item_info | The item. |
| plugin_data | The plugin data of the item, grouped by plugin name. |
| context | page (item details page) or modal (item details modal). |
Button options
| Option | What it does |
| title | Required. The button text. HTML is removed. |
| url | Required. It must start with http://, https://, mailto: or tel:. A link that starts with / opens a page of this app, for example /store. |
| icon | Optional. A feather icon name, for example eye, book-open, life-buoy. |
| new_tab | Optional. true or false. Links to other sites open in a new tab by default. |
| style | Optional. default, primary, info, success, warning, danger or dark. For a light colored button use soft-blue, soft-indigo, soft-sky, soft-teal, soft-coral, soft-orange, soft-amber, soft-violet or soft-slate. The default is default. |
| full_width | Optional. On the details page, buttons show two in a row. Set true to give a button its own row. |
| sort | Optional. A number. Lower numbers show first. The default is 100. |
| show_media | Optional. Set true to open the item images and videos in a full screen viewer, like the file preview. Uploaded videos and video links (YouTube, Vimeo, Loom, Dailymotion) play in the viewer. You don't need a url. If the item has no images or videos, the button is not shown. |
A button with a missing title or a wrong URL is not shown.
Show a Screenshots button
For example, show a Screenshots button when the item has no live preview link:
if (!get_array_value($links, "preview_url")) {
$buttons[] = array("title" => "Screenshots", "show_media" => true, "icon" => "image", "sort" => 10);
}
The images and videos show in the same order as on the item page. Users can move to the next or previous one with the arrows, and close the viewer with the Esc key. A video stops when the user moves to another one.
Show your own HTML
To show something else under the buttons, use the app_hook_store_item_details_buy_panel_extension action. It gets an array with item_info and context.
app_hooks()->add_action('app_hook_store_item_details_buy_panel_extension', function ($args) {
echo 'Free updates for 1 year.
';
});
Escape every value you print with esc().