Automattic\WooCommerce\Blocks\BlockTypes\AddToCartWithOptions
AddToCartWithOptions::render_interactivity_notices_region
Render interactivity API powered notices that can be added client-side. This reuses classes from the woocommerce/store-notices block to ensure style consistency.
Method of the class: AddToCartWithOptions{}
No Hooks.
Returns
String. The rendered store notices HTML.
Usage
// protected - for code of main (parent) or child class $result = $this->render_interactivity_notices_region( $form_html );
- $form_html(string) (required)
- The form HTML.
AddToCartWithOptions::render_interactivity_notices_region() AddToCartWithOptions::render interactivity notices region code WC 10.7.0
<?php
protected function render_interactivity_notices_region( $form_html ) {
$context_directive = wp_interactivity_data_wp_context(
array(
'notices' => array(),
)
);
ob_start();
?>
<div data-wp-interactive="woocommerce/store-notices" class="wc-block-components-notices alignwide" <?php echo $context_directive; // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped ?>>
<template data-wp-each--notice="context.notices" data-wp-each-key="context.notice.id">
<div
class="wc-block-components-notice-banner"
data-wp-class--is-error="state.isError"
data-wp-class--is-success="state.isSuccess"
data-wp-class--is-info="state.isInfo"
data-wp-class--is-dismissible="context.notice.dismissible"
data-wp-bind--role="state.role"
data-wp-watch="callbacks.injectIcon"
>
<div class="wc-block-components-notice-banner__content">
<span data-wp-init="callbacks.renderNoticeContent" aria-live="assertive" aria-atomic="true"></span>
</div>
<button
data-wp-bind--hidden="!context.notice.dismissible"
class="wc-block-components-button wp-element-button wc-block-components-notice-banner__dismiss contained"
aria-label="<?php esc_attr_e( 'Dismiss this notice', 'woocommerce' ); ?>"
data-wp-on--click="actions.removeNotice"
>
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24">
<path d="M13 11.8l6.1-6.3-1-1-6.1 6.2-6.1-6.2-1 1 6.1 6.3-6.5 6.7 1 1 6.5-6.6 6.5 6.6 1-1z" />
</svg>
</button>
</div>
</template>
<?php echo $form_html; // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped ?>
</div>
<?php
return ob_get_clean();
}