PluginProbe
bBlocks – Essential Gutenberg Blocks & Patterns Collection / 2.1.10
bBlocks – Essential Gutenberg Blocks & Patterns Collection v2.1.10
2.1.10 2.1.9 2.1.8 2.1.7 2.1.6 2.1.5 2.1.4 2.1.3 2.1.2 2.1.1 2.1.0 2.0.43 2.0.42 2.0.41 2.0.40 2.0.39 2.0.38 trunk 1.0 1.1 1.2 1.3 1.4 1.5 1.5.1 All 110 releases
b-blocks / build / woo-add-to-cart / render.php

render.php in bBlocks – Essential Gutenberg Blocks & Patterns Collection 2.1.10, at build/woo-add-to-cart/render.php

35 lines 1.1 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 use BBlocks\Inc\Blocks\WooAddToCart;
3 use BBlocks\Inc\Sanitize;
4
5 if ( ! class_exists( WooAddToCart::class ) || ! function_exists( 'wc_get_product' ) ) {
6 return;
7 }
8
9 $id = wp_unique_id( 'bBlocksWooAddToCart-' );
10 $attributes = WooAddToCart::frontendAttributes( $attributes, isset( $block ) ? $block : null );
11
12 if ( ! $attributes ) {
13 return;
14 }
15
16 $attributes = Sanitize::attributes( $attributes );
17
18 $json = wp_json_encode( $attributes, JSON_HEX_TAG | JSON_HEX_AMP | JSON_HEX_APOS | JSON_HEX_QUOT );
19 ?>
20 <div
21 <?php // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped -- get_block_wrapper_attributes() is properly escaped. ?>
22 <?php echo get_block_wrapper_attributes(); ?>
23 id='<?php echo esc_attr( $id ); ?>'
24 data-attributes='<?php echo esc_attr( $json ); ?>'
25 >
26 <?php
27 // Without JavaScript the block cannot render; the product page still sells
28 // it. view.js replaces this with the block.
29 $productUrl = $attributes['product']['url'] ?? '';
30 if ( $productUrl ) :
31 ?>
32 <noscript><a href='<?php echo esc_url( $productUrl ); ?>'><?php echo esc_html__( 'View product', 'b-blocks' ); ?></a></noscript>
33 <?php endif; ?>
34 </div>
35