Automattic\WooCommerce\Blocks\BlockTypes

Wishlist::render_ssr_add_to_cartprivateWC 1.0

SSR-mode markup for the "Add to cart" action button. Always emits the wrapper so iAPI can toggle hidden after hydration without swapping the row out. Starts hidden when the row isn't purchasable.

Method of the class: Wishlist{}

No Hooks.

Returns

String.

Usage

// private - for code of main (parent) class only
$result = $this->render_ssr_add_to_cart( $item ): string;
$item(array) (required)
.

Wishlist::render_ssr_add_to_cart() code WC 10.9.1

<?php
private function render_ssr_add_to_cart( array $item ): string {
	$is_hidden = empty( $item['is_purchasable'] );
	ob_start();
	?>
	<div
		class="wp-block-button wc-block-components-product-button"
		data-wp-bind--hidden="state.isAddToCartHidden"
		<?php
		if ( $is_hidden ) {
			echo 'hidden';
		}
		?>
	>
		<button
			type="button"
			class="wp-block-button__link wp-element-button add_to_cart_button wc-block-components-product-button__button"
			data-wp-on--click="actions.onClickAddToCart"
			data-wp-bind--disabled="state.isCurrentItemPending"
		>
			<?php echo esc_html( $this->get_add_to_cart_label() ); ?>
		</button>
	</div>
	<?php
	return (string) ob_get_clean();
}