'admin/BlockEditor/Buttons/AddToCartButtonBlockEditor.jsx', 'dependencies' => ['wp-blocks', 'wp-components'] ] ]; } public function getStyles(): array { return [ 'admin/BlockEditor/Buttons/style/button-block-editor.scss' ]; } public function supports(): array { return [ 'html' => false, 'typography' => [ 'fontSize' => true, 'lineHeight' => true ], 'spacing' => [ 'margin' => true, 'padding' => true ], 'color' => [ 'text' => true, 'background' => true, ], '__experimentalBorder' => [ 'color' => true, 'radius' => true, 'style' => true, 'width' => true, ], 'shadow' => true ]; } public function localizeData(): array { return [ $this->getLocalizationKey() => [ 'slug' => $this->slugPrefix, 'name' => static::getEditorName(), 'title' => __('Add to Cart', 'fluent-cart'), 'description' => __('A custom button block with product selection and automatic link assignment.', 'fluent-cart'), 'placeholder_image' => Vite::getAssetUrl('images/placeholder.svg'), ], 'fluent_cart_block_translation' => TransStrings::blockStrings(), ]; } public function render(array $shortCodeAttribute, $block = null) { AssetLoader::loadSingleProductAssets(); $variantIds = Arr::get($shortCodeAttribute, 'variant_ids', []); $variantId = Arr::get($variantIds, 0); if (!$variantId) { if(Helper::isAdminUser()){ return '
' . esc_html__('No variant selected', 'fluent-cart') . '
'; } return ''; } $variant = ProductVariation::query()->find($variantId); if (!$variant) { if(Helper::isAdminUser()){ return '' . esc_html__('Invalid variant', 'fluent-cart') . '
'; } return ''; } $product = Product::query()->find($variant->post_id); if (!$product) { if(Helper::isAdminUser()){ return '' . esc_html__('Product not found', 'fluent-cart') . '
'; } return ''; } ob_start(); (new ProductRenderer($product))->renderAddToCartButtonBlock($shortCodeAttribute); return ob_get_clean(); } }