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(); ?>
> renderNameFields(); $renderer->renderB2BToggle(); $renderer->renderCreateAccountField(); ?>
getCart(); if (empty(Arr::get($cart, 'cart_data', []))) { return ''; } $innerBlocksContent = ''; if ($block instanceof \WP_Block && !empty($block->inner_blocks)) { ob_start(); ?>
> inner_blocks as $inner_block) { if (isset($inner_block->parsed_block)) { echo $inner_block->render(); } } ?>
getCart(); $addressTitle = Arr::get($attributes, 'addressTitle'); if (empty(Arr::get($cart, 'cart_data', []))) { return ''; } ob_start(); ?>
> renderBillingAddressFields($addressTitle); ?>
getCart(); $addressTitle = Arr::get($attributes, 'addressTitle'); if (empty(Arr::get($cart, 'cart_data', [])) || !$cart->requireShipping()) { return ''; } ob_start(); ?>
> renderShippingAddressFields($addressTitle); ?>
getCart(); $title = Arr::get($attributes, 'ship_to_different_title'); if (empty(Arr::get($cart, 'cart_data', [])) || !$cart->requireShipping()) { return ''; } ob_start(); ?>
> renderShipToDifferentField([ 'title' => $title, 'wrapper_atts'=> $atts, ]); ?>
getCart(); if (empty(Arr::get($cart, 'cart_data', []))) { return ''; } $class = $cart->requireShipping() ? '' : 'is-hidden'; $atts = get_block_wrapper_attributes([ 'class' => 'fct_checkout_shipping_methods ' . $class ]); ob_start(); ?>
> renderShippingOptions(); ?>
getCart(); if (empty(Arr::get($cart, 'cart_data', []))) { return ''; } $atts = get_block_wrapper_attributes([ 'class' => 'fct_checkout_payment_methods', 'data-fluent-cart-checkout-payment-methods' => '' ]); ob_start(); ?> $cart]); ?>
> renderPaymentMethods(); ?>
$cart]); ?> getCart(); if (empty(Arr::get($cart, 'cart_data', []))) { return ''; } $title = Arr::get($attributes, 'terms_title'); $atts = get_block_wrapper_attributes(); ob_start(); ?>
> agreeTerms([ 'title' => $title, 'wrapper_atts'=> $atts, ]); ?>
getCart(); if (empty(Arr::get($cart, 'cart_data', []))) { return ''; } $atts = get_block_wrapper_attributes(); ob_start(); (new CheckoutRenderer($cart))->renderCheckoutButton($atts); return ob_get_clean(); } public function renderCheckoutOrderNotesField($attributes, $content, $block) { $cart = $this->getCart(); if (empty(Arr::get($cart, 'cart_data', []))) { return ''; } $atts = get_block_wrapper_attributes(); $title = Arr::get($attributes, 'title'); ob_start(); ?>
> renderOrderNoteField($title); ?>
getCart(); if (empty(Arr::get($cart, 'cart_data', []))) { return ''; } $atts = get_block_wrapper_attributes([ 'class' => 'fct_checkout_summary' ]); ob_start(); ?>
>
render(); ?>
getCart(); if (empty(Arr::get($cart, 'cart_data', []))) { return ''; } $atts = get_block_wrapper_attributes([ 'class' => 'fct_items_wrapper', 'data-fluent-cart-checkout-item-wrapper' => '' ]); ob_start(); ?>
> renderItemsLists(); ?>
getCart(); if (empty(Arr::get($cart, 'cart_data', []))) { return ''; } $innerBlocksContent = ''; if ($block instanceof \WP_Block && !empty($block->inner_blocks)) { ob_start(); ?>
getCart(); if (empty(Arr::get($cart, 'cart_data', []))) { return ''; } $atts = get_block_wrapper_attributes(); ob_start(); (new CartSummaryRender($cart))->renderSubtotal($atts); return ob_get_clean(); } public function renderCheckoutShipping($attributes, $content, $block) { $cart = $this->getCart(); if (empty(Arr::get($cart, 'cart_data', []))) { return ''; } $atts = get_block_wrapper_attributes([ 'class' => $cart->getShippingTotal() === 0 ? 'shipping-charge-hidden' : '', 'data-fluent-cart-checkout-shipping-amount-wrapper' => '' ]); ob_start(); (new CartSummaryRender($cart))->renderShipping($atts); return ob_get_clean(); } public function renderCheckoutFees($attributes, $content, $block) { $cart = $this->getCart(); if (empty(Arr::get($cart, 'cart_data', []))) { return ''; } ob_start(); (new CartSummaryRender($cart))->renderFees(); return ob_get_clean(); } public function renderCheckoutCoupon($attributes, $content, $block) { $cart = $this->getCart(); if (empty(Arr::get($cart, 'cart_data', []))) { return ''; } $atts = get_block_wrapper_attributes([ 'data-fluent-cart-checkout-page-applied-coupon' => '' ]); ob_start(); ?>
  • > showCouponField(); ?>
  • getCart(); if (empty(Arr::get($cart, 'cart_data', []))) { return ''; } ob_start(); (new CartSummaryRender($cart))->showUpgradeDiscount(); (new CartSummaryRender($cart))->showProrateCredit(); (new CartSummaryRender($cart))->showManualDiscount(); return ob_get_clean(); } public function renderCheckoutTax($attributes, $content, $block) { $cart = $this->getCart(); if (empty(Arr::get($cart, 'cart_data', []))) { return ''; } $atts = get_block_wrapper_attributes(); ob_start(); (new TaxModule())->renderTaxRow($cart, $atts); return ob_get_clean(); } public function renderCheckoutShippingTax($attributes, $content, $block) { $cart = $this->getCart(); if (empty(Arr::get($cart, 'cart_data', []))) { return ''; } $atts = get_block_wrapper_attributes(); ob_start(); (new TaxModule())->renderShippingTaxRow($cart, $atts); return ob_get_clean(); } public function renderCheckoutTotal($attributes, $content, $block) { $cart = $this->getCart(); if (empty(Arr::get($cart, 'cart_data', []))) { return ''; } $atts = get_block_wrapper_attributes([ 'class' => 'fct_summary_items_total', 'data-fluent-cart-checkout-page-current-total' => '' ]); ob_start(); (new CartSummaryRender($cart))->renderTotal($atts); return ob_get_clean(); } public function renderCheckoutOrderBump($attributes, $content, $block) { if (!App::isProActive() || !ModuleSettings::isActive('order_bump')) { return ''; } $cart = $this->getCart(); if (empty(Arr::get($cart, 'cart_data', []))) { return ''; } // A cart bound to an existing payment (custom payment link, renewal invoice, early // installment) or already carrying an upgrade cannot take new items — the // apply_order_bump handler refuses it, so rendering the bump would only offer a // control that fails. Same predicate on both sides so they cannot drift. if (!$cart->acceptsAdditionalItems()) { return ''; } $atts = get_block_wrapper_attributes(); $title = Arr::get($attributes, 'section_title'); ob_start(); ?>
    > maybeShowBumps([ 'cart' => $cart, 'section_title' => $title ]); ?>
    getLocalizationKey() => [ 'blocks' => Arr::except($this->getInnerBlocks(), ['callback']), ], 'fluentcart_single_product_vars' => [ 'trans' => TransStrings::singleProductPageString(), 'cart_button_text' => App::storeSettings()->get('cart_button_text', __('Add To Cart', 'fluent-cart')), 'out_of_stock_button_text' => App::storeSettings()->get('out_of_stock_button_text', __('Not Available', 'fluent-cart')), 'in_stock_status' => Helper::IN_STOCK, 'out_of_stock_status' => Helper::OUT_OF_STOCK, 'enable_image_zoom' => (new StoreSettings())->get('enable_image_zoom_in_single_product'), 'enable_image_zoom_in_modal' => (new StoreSettings())->get('enable_image_zoom_in_modal') ] ]; } public function getStyles(): array { return [ 'public/checkout/style/checkout.scss', 'public/components/select/style/style.scss' ]; } public function getScripts(): array { $scripts = [ [ 'source' => 'admin/BlockEditor/ReactSupport.js', 'dependencies' => ['wp-blocks', 'wp-components'] ], [ 'source' => 'admin/BlockEditor/Checkout/InnerBlocks/InnerBlocks.jsx', 'dependencies' => ['wp-blocks', 'wp-components', 'wp-block-editor'] ] ]; return $scripts; } protected function generateEnqueueSlug(): string { return 'fluent_cart_checkout_inner_blocks'; } }