cart === null) { $this->cart = CartHelper::getCart(); } return $this->cart; } public static function textBlockSupport(): array { return [ 'html' => false, 'align' => ['left', 'center', 'right'], 'typography' => [ 'fontSize' => true, 'lineHeight' => true ], 'spacing' => [ 'margin' => true, 'padding' => true ], 'color' => [ 'text' => true, ], '__experimentalBorder' => [ 'radius' => true, 'color' => true, 'width' => true, 'style' => true ] ]; } public static function buttonBlockSupport(): array { return [ 'html' => false, 'align' => ['left', 'center', 'right'], 'typography' => [ 'fontSize' => true, 'lineHeight' => true, 'fontWeight' => true, 'textTransform' => true, ], 'spacing' => [ 'margin' => true, 'padding' => true, ], 'color' => [ 'text' => true, 'background' => true, ], '__experimentalBorder' => [ 'radius' => true, 'color' => true, 'width' => true, 'style' => true ], 'shadow' => true, ]; } public static function register() { $self = new self(); $blocks = $self->getInnerBlocks(); foreach ($blocks as $block) { register_block_type($block['slug'], [ 'apiVersion' => 3, 'api_version' => 3, 'version' => 3, 'title' => $block['title'], 'category' => 'fluent-cart', 'parent' => array_merge($block['parent'] ?? [], [static::$parentBlock]), 'render_callback' => $block['callback'], 'supports' => Arr::get($block, 'supports', []), 'attributes' => Arr::get($block, 'attributes', []), 'uses_context' => Arr::get($block, 'uses_context', []), ]); } add_action('enqueue_block_editor_assets', function () use ($self) { $self->enqueueScripts(); }); } public function getInnerBlocks(): array { return [ [ 'title' => __('Checkout Name Fields', 'fluent-cart'), 'slug' => 'fluent-cart/checkout-name-fields', 'callback' => [$this, 'renderCheckoutNameFields'], 'component' => 'CheckoutNameFieldsBlock', 'icon' => 'editor-code', 'supports' => [ 'html' => false, 'typography' => [ 'fontSize' => false, 'lineHeight' => false ], 'spacing' => [ 'margin' => true, 'padding' => true ], 'color' => [ 'text' => false, 'background' => true, ], ], 'parent' => [ 'fluent-cart/checkout', 'core/column', 'core/group' ], ], [ 'title' => __('Checkout Create Account Field', 'fluent-cart'), 'slug' => 'fluent-cart/checkout-create-account-field', 'callback' => [$this, 'renderCheckoutCreateAccountField'], 'component' => 'CheckoutCreateAccountFieldBlock', 'icon' => 'editor-code', 'supports' => static::textBlockSupport(), 'parent' => [ 'fluent-cart/checkout', 'core/column', 'core/group' ], ], [ 'title' => __('Checkout Address Fields', 'fluent-cart'), 'slug' => 'fluent-cart/checkout-address-fields', 'callback' => [$this, 'renderCheckoutAddressFields'], 'component' => 'CheckoutAddressFieldsBlock', 'icon' => 'editor-code', 'supports' => [ 'html' => false, 'typography' => [ 'fontSize' => false, 'lineHeight' => false ], 'spacing' => [ 'margin' => true, 'padding' => true ], 'color' => [ 'text' => false, 'background' => true, ], '__experimentalBorder' => [ 'radius' => true, 'color' => true, 'width' => true, 'style' => true ] ], 'parent' => [ 'fluent-cart/checkout', 'core/column', 'core/group' ], ], [ 'title' => __('Billing Address Field', 'fluent-cart'), 'slug' => 'fluent-cart/checkout-billing-address-field', 'callback' => [$this, 'renderCheckoutBillingAddressField'], 'component' => 'CheckoutBillingAddressFieldBlock', 'icon' => 'editor-code', 'supports' => [ 'html' => false, 'typography' => [ 'fontSize' => false, 'lineHeight' => false ], 'spacing' => [ 'margin' => true, 'padding' => true ], 'color' => [ 'text' => false, 'background' => true, ], '__experimentalBorder' => [ 'radius' => true, 'color' => true, 'width' => true, 'style' => true ] ], 'parent' => [ 'fluent-cart/checkout-address-fields' ], ], [ 'title' => __('Shipping Address Field', 'fluent-cart'), 'slug' => 'fluent-cart/checkout-shipping-address-field', 'callback' => [$this, 'renderCheckoutShippingAddressField'], 'component' => 'CheckoutShippingAddressFieldBlock', 'icon' => 'editor-code', 'supports' => [ 'html' => false, 'typography' => [ 'fontSize' => false, 'lineHeight' => false ], 'spacing' => [ 'margin' => true, 'padding' => true ], 'color' => [ 'text' => false, 'background' => true, ], '__experimentalBorder' => [ 'radius' => true, 'color' => true, 'width' => true, 'style' => true ] ], 'parent' => [ 'fluent-cart/checkout-address-fields' ], ], [ 'title' => __('Ship to Different Field', 'fluent-cart'), 'slug' => 'fluent-cart/checkout-ship-to-different-field', 'callback' => [$this, 'renderCheckoutShipToDifferentField'], 'component' => 'CheckoutShipToDifferentFieldBlock', 'icon' => 'editor-code', 'supports' => [ 'html' => false, 'align' => ['left', 'center', 'right'], 'typography' => [ 'fontSize' => true, 'lineHeight' => true ], 'spacing' => [ 'margin' => true, 'padding' => true ], 'color' => [ 'text' => true, ], '__experimentalBorder' => [ 'radius' => true, 'color' => true, 'width' => true, 'style' => true ] ], 'parent' => [ 'fluent-cart/checkout-address-fields' ], ], [ 'title' => __('Checkout Shipping Methods', 'fluent-cart'), 'slug' => 'fluent-cart/checkout-shipping-methods', 'callback' => [$this, 'renderCheckoutShippingMethods'], 'component' => 'CheckoutShippingMethodsBlock', 'icon' => 'editor-code', 'supports' => static::textBlockSupport(), 'parent' => [ 'fluent-cart/checkout', 'core/column', 'core/group' ], ], [ 'title' => __('Checkout Payment Methods', 'fluent-cart'), 'slug' => 'fluent-cart/checkout-payment-methods', 'callback' => [$this, 'renderCheckoutPaymentMethods'], 'component' => 'CheckoutPaymentMethodsBlock', 'icon' => 'editor-code', 'supports' => static::textBlockSupport(), 'parent' => [ 'fluent-cart/checkout', 'core/column', 'core/group' ], ], [ 'title' => __('Checkout Agree Terms Field', 'fluent-cart'), 'slug' => 'fluent-cart/checkout-agree-terms-field', 'callback' => [$this, 'renderCheckoutAgreeTermsField'], 'component' => 'CheckoutAgreeTermsFieldBlock', 'icon' => 'editor-code', 'supports' => [ 'html' => false, 'align' => ['left', 'center', 'right'], 'typography' => [ 'fontSize' => true, 'lineHeight' => true ], 'spacing' => [ 'margin' => true ], 'color' => [ 'text' => true, ] ], 'parent' => [ 'fluent-cart/checkout', 'core/column', 'core/group' ], ], [ 'title' => __('Checkout Submit Button', 'fluent-cart'), 'slug' => 'fluent-cart/checkout-submit-button', 'callback' => [$this, 'renderCheckoutSubmitButton'], 'component' => 'CheckoutSubmitButtonBlock', 'icon' => 'editor-code', 'supports' => static::buttonBlockSupport(), 'parent' => [ 'fluent-cart/checkout', 'core/column', 'core/group' ], ], [ 'title' => __('Checkout Order Notes Field', 'fluent-cart'), 'slug' => 'fluent-cart/checkout-order-notes-field', 'callback' => [$this, 'renderCheckoutOrderNotesField'], 'component' => 'CheckoutOrderNotesFieldBlock', 'icon' => 'editor-code', 'supports' => static::textBlockSupport(), 'parent' => [ 'fluent-cart/checkout', 'core/column', 'core/group' ], ], [ 'title' => __('Checkout Summary', 'fluent-cart'), 'slug' => 'fluent-cart/checkout-summary', 'callback' => [$this, 'renderCheckoutSummary'], 'component' => 'CheckoutSummaryBlock', 'icon' => 'editor-code', 'supports' => static::textBlockSupport(), 'parent' => [ 'fluent-cart/checkout', 'core/column', 'core/group' ], ], [ 'title' => __('Order Summary', 'fluent-cart'), 'slug' => 'fluent-cart/checkout-order-summary', 'callback' => [$this, 'renderCheckoutOrderSummary'], 'component' => 'CheckoutOrderSummaryBlock', 'icon' => 'editor-code', 'supports' => static::textBlockSupport(), 'parent' => [ 'fluent-cart/checkout-summary' ], ], [ 'title' => __('Summary Footer', 'fluent-cart'), 'slug' => 'fluent-cart/checkout-summary-footer', 'callback' => [$this, 'renderCheckoutSummaryFooter'], 'component' => 'CheckoutSummaryFooterBlock', 'icon' => 'editor-code', 'supports' => static::textBlockSupport(), 'parent' => [ 'fluent-cart/checkout-summary' ], ], [ 'title' => __('Subtotal', 'fluent-cart'), 'slug' => 'fluent-cart/checkout-subtotal', 'callback' => [$this, 'renderCheckoutSubtotal'], 'component' => 'CheckoutSubtotalBlock', 'icon' => 'editor-code', 'supports' => static::textBlockSupport(), 'parent' => [ 'fluent-cart/checkout-summary-footer' ], ], [ 'title' => __('Shipping', 'fluent-cart'), 'slug' => 'fluent-cart/checkout-shipping', 'callback' => [$this, 'renderCheckoutShipping'], 'component' => 'CheckoutShippingBlock', 'icon' => 'editor-code', 'supports' => static::textBlockSupport(), 'parent' => [ 'fluent-cart/checkout-summary-footer' ], ], [ 'title' => __('Fees', 'fluent-cart'), 'slug' => 'fluent-cart/checkout-fees', 'callback' => [$this, 'renderCheckoutFees'], 'component' => 'CheckoutFeesBlock', 'icon' => 'editor-code', 'supports' => static::textBlockSupport(), 'parent' => [ 'fluent-cart/checkout-summary-footer' ], ], [ 'title' => __('Coupon', 'fluent-cart'), 'slug' => 'fluent-cart/checkout-coupon', 'callback' => [$this, 'renderCheckoutCoupon'], 'component' => 'CheckoutCouponBlock', 'icon' => 'editor-code', 'supports' => static::textBlockSupport(), 'parent' => [ 'fluent-cart/checkout-summary-footer' ], ], [ 'title' => __('Manual Discount', 'fluent-cart'), 'slug' => 'fluent-cart/checkout-manual-discount', 'callback' => [$this, 'renderCheckoutManualDiscount'], 'component' => 'CheckoutManualDiscountBlock', 'icon' => 'editor-code', 'supports' => static::textBlockSupport(), 'parent' => [ 'fluent-cart/checkout-summary-footer' ], ], [ 'title' => __('Tax', 'fluent-cart'), 'slug' => 'fluent-cart/checkout-tax', 'callback' => [$this, 'renderCheckoutTax'], 'component' => 'CheckoutTaxBlock', 'icon' => 'editor-code', 'supports' => static::textBlockSupport(), 'parent' => [ 'fluent-cart/checkout-summary-footer' ], ], [ 'title' => __('Shipping Tax', 'fluent-cart'), 'slug' => 'fluent-cart/checkout-shipping-tax', 'callback' => [$this, 'renderCheckoutShippingTax'], 'component' => 'CheckoutShippingTaxBlock', 'icon' => 'editor-code', 'supports' => static::textBlockSupport(), 'parent' => [ 'fluent-cart/checkout-summary-footer' ], ], [ 'title' => __('Total', 'fluent-cart'), 'slug' => 'fluent-cart/checkout-total', 'callback' => [$this, 'renderCheckoutTotal'], 'component' => 'CheckoutTotalBlock', 'icon' => 'editor-code', 'supports' => static::textBlockSupport(), 'parent' => [ 'fluent-cart/checkout-summary-footer' ], ], [ 'title' => __('Checkout Order Bump', 'fluent-cart'), 'slug' => 'fluent-cart/checkout-order-bump', 'callback' => [$this, 'renderCheckoutOrderBump'], 'component' => 'CheckoutOrderBumpBlock', 'icon' => 'editor-code', 'supports' => [ 'html' => false, 'align' => ['left', 'center', 'right'], 'typography' => [ 'fontSize' => false, 'lineHeight' => false ], 'spacing' => [ 'margin' => true, 'padding' => true ], 'color' => [ 'text' => false, 'background' => true, ], '__experimentalBorder' => [ 'radius' => true, 'color' => true, 'width' => true, 'style' => true ] ], 'parent' => [ 'fluent-cart/checkout', 'core/column', 'core/group' ], ], [ 'title' => __('Checkout EU VAT', 'fluent-cart'), 'slug' => 'fluent-cart/checkout-eu-vat', 'callback' => [$this, 'renderCheckoutEuVat'], 'component' => 'CheckoutEuVatBlock', 'icon' => 'editor-code', 'supports' => [ 'html' => false, 'spacing' => [ 'margin' => true, 'padding' => true ], '__experimentalBorder' => [ 'radius' => true, 'color' => true, 'width' => true, 'style' => true ] ], 'parent' => [ 'fluent-cart/checkout', 'core/column', 'core/group' ], ] ]; } public function renderCheckoutNameFields($attributes, $content, $block) { $atts = get_block_wrapper_attributes(); $cart = $this->getCart(); if (empty(Arr::get($cart, 'cart_data', []))) { return ''; } ob_start(); ?>