Accordion
1 year ago
AddToCartWithOptions
1 week ago
OrderConfirmation
2 months ago
ProductCollection
3 weeks ago
Reviews
2 months ago
AbstractBlock.php
4 weeks ago
AbstractDynamicBlock.php
2 years ago
AbstractInnerBlock.php
1 year ago
AbstractProductGrid.php
3 months ago
ActiveFilters.php
2 years ago
AddToCartForm.php
4 weeks ago
AddToWishlistButton.php
4 weeks ago
AllProducts.php
2 years ago
AllReviews.php
2 years ago
AtomicBlock.php
2 years ago
AttributeFilter.php
1 year ago
Breadcrumbs.php
1 year ago
Cart.php
2 months ago
CartAcceptedPaymentMethodsBlock.php
2 years ago
CartCrossSellsBlock.php
2 years ago
CartCrossSellsProductsBlock.php
2 years ago
CartExpressPaymentBlock.php
1 year ago
CartItemsBlock.php
2 years ago
CartLineItemsBlock.php
2 years ago
CartLink.php
2 months ago
CartOrderSummaryBlock.php
2 years ago
CartOrderSummaryCouponFormBlock.php
2 years ago
CartOrderSummaryDiscountBlock.php
2 years ago
CartOrderSummaryFeeBlock.php
2 years ago
CartOrderSummaryHeadingBlock.php
2 years ago
CartOrderSummaryShippingBlock.php
2 years ago
CartOrderSummarySubtotalBlock.php
2 years ago
CartOrderSummaryTaxesBlock.php
2 years ago
CartOrderSummaryTotalsBlock.php
2 years ago
CartTotalsBlock.php
2 years ago
CatalogSorting.php
4 weeks ago
CategoryDescription.php
2 months ago
CategoryTitle.php
2 months ago
Checkout.php
2 months ago
CheckoutActionsBlock.php
1 year ago
CheckoutAdditionalInformationBlock.php
2 years ago
CheckoutBillingAddressBlock.php
2 years ago
CheckoutContactInformationBlock.php
2 years ago
CheckoutExpressPaymentBlock.php
9 months ago
CheckoutFieldsBlock.php
2 years ago
CheckoutOrderNoteBlock.php
2 years ago
CheckoutOrderSummaryBlock.php
2 years ago
CheckoutOrderSummaryCartItemsBlock.php
2 years ago
CheckoutOrderSummaryCouponFormBlock.php
2 years ago
CheckoutOrderSummaryDiscountBlock.php
2 years ago
CheckoutOrderSummaryFeeBlock.php
2 years ago
CheckoutOrderSummaryShippingBlock.php
2 years ago
CheckoutOrderSummarySubtotalBlock.php
2 years ago
CheckoutOrderSummaryTaxesBlock.php
2 years ago
CheckoutOrderSummaryTotalsBlock.php
2 years ago
CheckoutPaymentBlock.php
2 years ago
CheckoutPickupOptionsBlock.php
2 years ago
CheckoutShippingAddressBlock.php
2 years ago
CheckoutShippingMethodBlock.php
2 years ago
CheckoutShippingMethodsBlock.php
2 years ago
CheckoutTermsBlock.php
2 years ago
CheckoutTotalsBlock.php
2 years ago
ClassicShortcode.php
1 year ago
ClassicTemplate.php
4 months ago
ComingSoon.php
1 year ago
CouponCode.php
2 months ago
CustomerAccount.php
3 months ago
Dropdown.php
4 weeks ago
EmailContent.php
5 months ago
EmptyCartBlock.php
2 years ago
EmptyMiniCartContentsBlock.php
11 months ago
EnableBlockJsonAssetsTrait.php
1 year ago
FeaturedCategory.php
7 months ago
FeaturedItem.php
7 months ago
FeaturedProduct.php
7 months ago
FilledCartBlock.php
2 years ago
FilledMiniCartContentsBlock.php
4 months ago
FilterWrapper.php
2 years ago
HandpickedProducts.php
1 year ago
MiniCart.php
4 weeks ago
MiniCartCartButtonBlock.php
11 months ago
MiniCartCheckoutButtonBlock.php
11 months ago
MiniCartContents.php
3 months ago
MiniCartFooterBlock.php
4 weeks ago
MiniCartItemsBlock.php
11 months ago
MiniCartProductsTableBlock.php
4 weeks ago
MiniCartShoppingButtonBlock.php
9 months ago
MiniCartTitleBlock.php
11 months ago
MiniCartTitleItemsCounterBlock.php
11 months ago
MiniCartTitleLabelBlock.php
11 months ago
NextPreviousButtons.php
5 months ago
PageContentWrapper.php
2 years ago
PaymentMethodIcons.php
11 months ago
PriceFilter.php
1 year ago
ProceedToCheckoutBlock.php
2 years ago
ProductAverageRating.php
1 year ago
ProductBestSellers.php
2 years ago
ProductButton.php
2 months ago
ProductCategories.php
4 weeks ago
ProductCategory.php
2 years ago
ProductDescription.php
9 months ago
ProductDetails.php
5 months ago
ProductFilterActive.php
4 weeks ago
ProductFilterAttribute.php
4 weeks ago
ProductFilterCheckboxList.php
4 weeks ago
ProductFilterChips.php
4 weeks ago
ProductFilterClearButton.php
4 weeks ago
ProductFilterPrice.php
4 weeks ago
ProductFilterPriceSlider.php
4 weeks ago
ProductFilterRating.php
4 weeks ago
ProductFilterRemovableChips.php
4 weeks ago
ProductFilterStatus.php
4 weeks ago
ProductFilterTaxonomy.php
4 weeks ago
ProductFilters.php
3 weeks ago
ProductGallery.php
4 weeks ago
ProductGalleryLargeImage.php
4 weeks ago
ProductGalleryThumbnails.php
4 weeks ago
ProductImage.php
4 weeks ago
ProductImageGallery.php
7 months ago
ProductMeta.php
1 year ago
ProductNew.php
2 years ago
ProductOnSale.php
2 years ago
ProductPrice.php
2 months ago
ProductQuery.php
4 weeks ago
ProductRating.php
1 year ago
ProductRatingCounter.php
1 year ago
ProductRatingStars.php
1 year ago
ProductResultsCount.php
2 months ago
ProductSKU.php
2 months ago
ProductSaleBadge.php
1 year ago
ProductSearch.php
10 months ago
ProductSpecifications.php
2 months ago
ProductStockIndicator.php
2 months ago
ProductSummary.php
7 months ago
ProductTag.php
2 years ago
ProductTemplate.php
2 months ago
ProductTitle.php
1 year ago
ProductTopRated.php
2 years ago
ProductsByAttribute.php
2 years ago
RatingFilter.php
2 years ago
RelatedProducts.php
3 months ago
ReviewsByCategory.php
2 years ago
ReviewsByProduct.php
2 years ago
SavedForLater.php
4 weeks ago
SingleProduct.php
2 months ago
StockFilter.php
2 years ago
StoreNotices.php
1 year ago
Wishlist.php
4 weeks ago
MiniCartFooterBlock.php
192 lines
| 1 | <?php |
| 2 | namespace Automattic\WooCommerce\Blocks\BlockTypes; |
| 3 | |
| 4 | use Automattic\WooCommerce\Admin\Features\Features; |
| 5 | |
| 6 | /** |
| 7 | * MiniCartFooterBlock class. |
| 8 | */ |
| 9 | class MiniCartFooterBlock extends AbstractInnerBlock { |
| 10 | /** |
| 11 | * Block name. |
| 12 | * |
| 13 | * @var string |
| 14 | */ |
| 15 | protected $block_name = 'mini-cart-footer-block'; |
| 16 | |
| 17 | /** |
| 18 | * Data passed through from server to client for block. |
| 19 | * |
| 20 | * @param array $attributes Any attributes that currently are available from the block. |
| 21 | * Note, this will be empty in the editor context when the block is |
| 22 | * not in the post content on editor load. |
| 23 | */ |
| 24 | protected function enqueue_data( array $attributes = array() ) { |
| 25 | parent::enqueue_data( $attributes ); |
| 26 | $description = $this->get_totals_item_description(); |
| 27 | if ( ! empty( $description ) ) { |
| 28 | $this->asset_data_registry->add( 'miniCartFooterDescription', $description ); |
| 29 | } |
| 30 | } |
| 31 | |
| 32 | /** |
| 33 | * Render experimental iAPI powered Mini-Cart Footer block. |
| 34 | * |
| 35 | * @param array $attributes Block attributes. |
| 36 | * @param string $content Block content. |
| 37 | * @param WP_Block $block Block instance. |
| 38 | * @return string Rendered block type output. |
| 39 | */ |
| 40 | protected function render_experimental_iapi_mini_cart_footer( $attributes, $content, $block ) { |
| 41 | ob_start(); |
| 42 | |
| 43 | $cart = $this->get_cart_instance(); |
| 44 | $subtotal_label = __( 'Subtotal', 'woocommerce' ); |
| 45 | $other_costs_label = $this->get_totals_item_description(); |
| 46 | $display_cart_price_including_tax = get_option( 'woocommerce_tax_display_cart' ) === 'incl'; |
| 47 | $subtotal = $display_cart_price_including_tax ? $cart->get_subtotal_tax() : $cart->get_subtotal(); |
| 48 | $formatted_subtotal = ''; |
| 49 | $html = new \WP_HTML_Tag_Processor( wc_price( $subtotal ) ); |
| 50 | $wrapper_attributes = get_block_wrapper_attributes( |
| 51 | array( |
| 52 | 'data-wp-interactive' => 'woocommerce/mini-cart-footer-block', |
| 53 | 'class' => 'wc-block-mini-cart__footer', |
| 54 | ) |
| 55 | ); |
| 56 | |
| 57 | if ( $html->next_tag( 'bdi' ) ) { |
| 58 | while ( $html->next_token() ) { |
| 59 | if ( '#text' === $html->get_token_name() ) { |
| 60 | $formatted_subtotal .= $html->get_modifiable_text(); |
| 61 | } |
| 62 | } |
| 63 | } |
| 64 | |
| 65 | wp_interactivity_state( |
| 66 | $this->get_full_block_name(), |
| 67 | array( |
| 68 | 'formattedSubtotal' => $formatted_subtotal, |
| 69 | ) |
| 70 | ); |
| 71 | |
| 72 | ?> |
| 73 | <div <?php echo $wrapper_attributes; // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped ?>> |
| 74 | <div class="wc-block-components-totals-item wc-block-mini-cart__footer-subtotal"> |
| 75 | <span class="wc-block-components-totals-item__label"> |
| 76 | <?php echo esc_html( $subtotal_label ); ?> |
| 77 | </span> |
| 78 | <span data-wp-text="woocommerce/mini-cart::state.formattedSubtotal" class="wc-block-formatted-money-amount wc-block-components-formatted-money-amount wc-block-components-totals-item__value notranslate"> |
| 79 | </span> |
| 80 | <div class="wc-block-components-totals-item__description"> |
| 81 | <?php echo esc_html( $other_costs_label ); ?> |
| 82 | </div> |
| 83 | </div> |
| 84 | <div class="wc-block-mini-cart__footer-actions"> |
| 85 | <?php |
| 86 | if ( empty( $content ) ) { |
| 87 | // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped |
| 88 | echo do_blocks( '<!-- wp:woocommerce/mini-cart-cart-button-block /--><!-- wp:woocommerce/mini-cart-checkout-button-block /-->' ); |
| 89 | } else { |
| 90 | // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped |
| 91 | echo $content; |
| 92 | } |
| 93 | ?> |
| 94 | </div> |
| 95 | </div> |
| 96 | <?php |
| 97 | return ob_get_clean(); |
| 98 | } |
| 99 | |
| 100 | /** |
| 101 | * Return the main instance of WC_Cart class. |
| 102 | * |
| 103 | * @return \WC_Cart CartController class instance. |
| 104 | */ |
| 105 | protected function get_cart_instance() { |
| 106 | $cart = WC()->cart; |
| 107 | |
| 108 | if ( $cart && $cart instanceof \WC_Cart ) { |
| 109 | return $cart; |
| 110 | } |
| 111 | |
| 112 | return null; |
| 113 | } |
| 114 | |
| 115 | /** |
| 116 | * Computes the total items description text based on which settings are enabled. |
| 117 | * |
| 118 | * @return string The description text for the total items, or empty string if none are enabled. |
| 119 | */ |
| 120 | private function get_totals_item_description() { |
| 121 | $taxes_enabled = wc_tax_enabled(); |
| 122 | $shipping_enabled = wc_shipping_enabled(); |
| 123 | $coupons_enabled = wc_coupons_enabled(); |
| 124 | |
| 125 | // All three enabled. |
| 126 | if ( $taxes_enabled && $shipping_enabled && $coupons_enabled ) { |
| 127 | return __( |
| 128 | 'Shipping, taxes, and discounts calculated at checkout.', |
| 129 | 'woocommerce' |
| 130 | ); |
| 131 | } |
| 132 | |
| 133 | // Shipping + taxes. |
| 134 | if ( $shipping_enabled && $taxes_enabled ) { |
| 135 | return __( |
| 136 | 'Shipping and taxes calculated at checkout.', |
| 137 | 'woocommerce' |
| 138 | ); |
| 139 | } |
| 140 | |
| 141 | // Shipping + discounts. |
| 142 | if ( $shipping_enabled && $coupons_enabled ) { |
| 143 | return __( |
| 144 | 'Shipping and discounts calculated at checkout.', |
| 145 | 'woocommerce' |
| 146 | ); |
| 147 | } |
| 148 | |
| 149 | // Taxes + discounts. |
| 150 | if ( $taxes_enabled && $coupons_enabled ) { |
| 151 | return __( |
| 152 | 'Taxes and discounts calculated at checkout.', |
| 153 | 'woocommerce' |
| 154 | ); |
| 155 | } |
| 156 | |
| 157 | // Only shipping. |
| 158 | if ( $shipping_enabled ) { |
| 159 | return __( 'Shipping calculated at checkout.', 'woocommerce' ); |
| 160 | } |
| 161 | |
| 162 | // Only taxes. |
| 163 | if ( $taxes_enabled ) { |
| 164 | return __( 'Taxes calculated at checkout.', 'woocommerce' ); |
| 165 | } |
| 166 | |
| 167 | // Only discounts. |
| 168 | if ( $coupons_enabled ) { |
| 169 | return __( 'Discounts calculated at checkout.', 'woocommerce' ); |
| 170 | } |
| 171 | |
| 172 | // None enabled. |
| 173 | return ''; |
| 174 | } |
| 175 | |
| 176 | /** |
| 177 | * Render the markup for the Mini-Cart Contents block. |
| 178 | * |
| 179 | * @param array $attributes Block attributes. |
| 180 | * @param string $content Block content. |
| 181 | * @param WP_Block $block Block instance. |
| 182 | * @return string Rendered block type output. |
| 183 | */ |
| 184 | protected function render( $attributes, $content, $block ) { |
| 185 | if ( Features::is_enabled( 'experimental-iapi-mini-cart' ) ) { |
| 186 | return $this->render_experimental_iapi_mini_cart_footer( $attributes, $content, $block ); |
| 187 | } |
| 188 | |
| 189 | return $content; |
| 190 | } |
| 191 | } |
| 192 |