| Server IP : 38.190.208.107 / Your IP : 216.73.217.46 Web Server : nginx/1.28.1 System : Linux ht2026040333114 6.1.0-10-amd64 #1 SMP PREEMPT_DYNAMIC Debian 6.1.37-1 (2023-07-03) x86_64 User : root ( 0) PHP Version : 8.2.28 Disable Function : passthru,exec,system,putenv,chroot,chgrp,chown,shell_exec,popen,proc_open,pcntl_exec,ini_alter,ini_restore,dl,openlog,syslog,readlink,symlink,popepassthru,pcntl_alarm,pcntl_fork,pcntl_waitpid,pcntl_wait,pcntl_wifexited,pcntl_wifstopped,pcntl_wifsignaled,pcntl_wifcontinued,pcntl_wexitstatus,pcntl_wtermsig,pcntl_wstopsig,pcntl_signal,pcntl_signal_dispatch,pcntl_get_last_error,pcntl_strerror,pcntl_sigprocmask,pcntl_sigwaitinfo,pcntl_sigtimedwait,pcntl_exec,pcntl_getpriority,pcntl_setpriority,imap_open,apache_setenv,eval,assert,passthru,system,exec,shell_exec,popen,proc_open MySQL : OFF | cURL : ON | WGET : OFF | Perl : OFF | Python : OFF | Sudo : OFF | Pkexec : OFF Directory : /www/wwwroot/wp.11/wp-content/plugins/woocommerce/src/Blocks/BlockTypes/ |
Upload File : |
<?php
namespace Automattic\WooCommerce\Blocks\BlockTypes;
use WC_Shortcode_Cart;
use WC_Shortcode_Checkout;
use WC_Frontend_Scripts;
/**
* Classic Shortcode class
*
* @internal
*/
class ClassicShortcode extends AbstractDynamicBlock {
/**
* Block name.
*
* @var string
*/
protected $block_name = 'classic-shortcode';
/**
* API version.
*
* @var string
*/
protected $api_version = '3';
/**
* Render method for the Classic Template block. This method will determine which template to render.
*
* @param array $attributes Block attributes.
* @param string $content Block content.
* @param WP_Block $block Block instance.
* @return string | void Rendered block type output.
*/
protected function render( $attributes, $content, $block ) {
if ( ! isset( $attributes['shortcode'] ) ) {
return;
}
/**
* We need to load the scripts here because when using block templates wp_head() gets run after the block
* template. As a result we are trying to enqueue required scripts before we have even registered them.
*
* @see https://github.com/woocommerce/woocommerce-gutenberg-products-block/issues/5328#issuecomment-989013447
*/
if ( class_exists( 'WC_Frontend_Scripts' ) ) {
$frontend_scripts = new WC_Frontend_Scripts();
$frontend_scripts::load_scripts();
}
if ( 'cart' === $attributes['shortcode'] ) {
return $this->render_cart( $attributes );
}
if ( 'checkout' === $attributes['shortcode'] ) {
return $this->render_checkout( $attributes );
}
return "You're using the ClassicShortcode block";
}
/**
* Get the list of classes to apply to this block.
*
* @param array $attributes Block attributes. Default empty array.
* @return string space-separated list of classes.
*/
protected function get_container_classes( $attributes = array() ) {
$classes = array( 'woocommerce', 'wp-block-group' );
if ( isset( $attributes['align'] ) ) {
$classes[] = "align{$attributes['align']}";
}
return implode( ' ', $classes );
}
/**
* Render method for rendering the cart shortcode.
*
* @param array $attributes Block attributes.
* @return string Rendered block type output.
*/
protected function render_cart( $attributes ) {
if ( ! isset( WC()->cart ) ) {
return '';
}
ob_start();
echo '<div class="' . esc_attr( $this->get_container_classes( $attributes ) ) . '">';
WC_Shortcode_Cart::output( array() );
echo '</div>';
return ob_get_clean();
}
/**
* Render method for rendering the checkout shortcode.
*
* @param array $attributes Block attributes.
* @return string Rendered block type output.
*/
protected function render_checkout( $attributes ) {
if ( ! isset( WC()->cart ) ) {
return '';
}
ob_start();
echo '<div class="' . esc_attr( $this->get_container_classes( $attributes ) ) . '">';
WC_Shortcode_Checkout::output( array() );
echo '</div>';
return ob_get_clean();
}
/**
* Get the frontend style handle for this block type.
*
* @return null
*/
protected function get_block_type_style() {
return null;
}
}