| 1 |
<?php |
| 2 |
namespace Sellkit\Blocks\Inner_Block; |
| 3 |
|
| 4 |
defined( 'ABSPATH' ) || exit; |
| 5 |
|
| 6 |
/** |
| 7 |
* Review Order class. |
| 8 |
* |
| 9 |
* @since 2.3.0 |
| 10 |
* @package Sellkit\Blocks\Inner_Block |
| 11 |
*/ |
| 12 |
class Checkout_Review_Order { |
| 13 |
/** |
| 14 |
* Checkout_Review_Order constructor. |
| 15 |
* |
| 16 |
* @since 2.3.0 |
| 17 |
*/ |
| 18 |
public function __construct() { |
| 19 |
remove_action( 'woocommerce_before_checkout_form', 'woocommerce_checkout_coupon_form', 10, 1 ); |
| 20 |
} |
| 21 |
|
| 22 |
/** |
| 23 |
* Register block meta. |
| 24 |
* |
| 25 |
* @since 2.3.0 |
| 26 |
*/ |
| 27 |
public function register_block_meta() { |
| 28 |
register_block_type_from_metadata( |
| 29 |
__DIR__ |
| 30 |
); |
| 31 |
} |
| 32 |
|
| 33 |
/** |
| 34 |
* Cart totals coupon label. |
| 35 |
* |
| 36 |
* @param string $label Label. |
| 37 |
* @param array $coupon \WC_Coupon. |
| 38 |
* @since 2.3.0 |
| 39 |
* @return string |
| 40 |
* |
| 41 |
* @SuppressWarnings(PHPMD.UnusedFormalParameter) |
| 42 |
*/ |
| 43 |
public function cart_totals_coupon_label( $label, $coupon ) { |
| 44 |
return sprintf( |
| 45 |
'%s<span class="sellkit-coupon-label">%s</span>', |
| 46 |
esc_html__( 'Discount', 'sellkit' ), |
| 47 |
esc_html( $coupon->get_code() ) |
| 48 |
); |
| 49 |
} |
| 50 |
|
| 51 |
/** |
| 52 |
* Render review order. |
| 53 |
* |
| 54 |
* @param string $content Block content. |
| 55 |
* @param array $attributes Block attributes. |
| 56 |
* @since 2.3.0 |
| 57 |
* @return string |
| 58 |
* |
| 59 |
* @SuppressWarnings(PHPMD.NPathComplexity) |
| 60 |
*/ |
| 61 |
public function checkout_review_order( $content, $attributes ) { |
| 62 |
ob_start(); |
| 63 |
|
| 64 |
if ( empty( WC()->cart ) ) { |
| 65 |
return; |
| 66 |
} |
| 67 |
do_action( 'woocommerce_checkout_before_order_review_heading' ); |
| 68 |
do_action( 'woocommerce_checkout_before_order_review' ); |
| 69 |
?> |
| 70 |
<div id="order_review" class="woocommerce-checkout-review-order <?php echo esc_attr( $attributes['customClassName'] ); ?>"> |
| 71 |
<?php do_action( 'sellkit-block-checkout-before-order-summary' ); ?> |
| 72 |
<?php do_action( 'sellkit-bundled-products-position' ); ?> |
| 73 |
|
| 74 |
<div id="sellkit-checkout-widget-order-review-wrap" > |
| 75 |
<table class="shop_table woocommerce-checkout-review-order-table" cellspacing="0"> |
| 76 |
<div class="sellkit-checkout-order-review-heading header heading"> |
| 77 |
<?php echo esc_html( $attributes['reviewHeadingText'] ); ?> |
| 78 |
</div> |
| 79 |
<thead> |
| 80 |
<?php ob_start(); ?> |
| 81 |
<tr> |
| 82 |
<th class="product-name"><?php esc_html_e( 'Product', 'sellkit' ); ?></th> |
| 83 |
<th class="product-total"><?php esc_html_e( 'Subtotal', 'sellkit' ); ?></th> |
| 84 |
</tr> |
| 85 |
<?php ob_get_clean(); ?> |
| 86 |
</thead> |
| 87 |
<tbody> |
| 88 |
<?php |
| 89 |
do_action( 'woocommerce_review_order_before_cart_contents' ); |
| 90 |
|
| 91 |
foreach ( WC()->cart->get_cart() as $cart_item_key => $cart_item ) { |
| 92 |
$_product = apply_filters( 'woocommerce_cart_item_product', $cart_item['data'], $cart_item, $cart_item_key ); |
| 93 |
|
| 94 |
if ( $_product && $_product->exists() && $cart_item['quantity'] > 0 && apply_filters( 'woocommerce_checkout_cart_item_visible', true, $cart_item, $cart_item_key ) ) { |
| 95 |
ob_start(); |
| 96 |
?> |
| 97 |
<tr class="<?php echo esc_attr( apply_filters( 'woocommerce_cart_item_class', 'cart_item', $cart_item, $cart_item_key ) ); ?>"> |
| 98 |
<td class="product-name"> |
| 99 |
<?php echo wp_kses_post( apply_filters( 'woocommerce_cart_item_name', $_product->get_name(), $cart_item, $cart_item_key ) ) . ' '; ?> |
| 100 |
<?php echo apply_filters( 'woocommerce_checkout_cart_item_quantity', ' <strong class="product-quantity">' . sprintf( '× %s', $cart_item['quantity'] ) . '</strong>', $cart_item, $cart_item_key ); // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped ?> |
| 101 |
<?php echo wc_get_formatted_cart_item_data( $cart_item ); // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped ?> |
| 102 |
</td> |
| 103 |
<td class="product-total"> |
| 104 |
<?php echo apply_filters( 'woocommerce_cart_item_subtotal', WC()->cart->get_product_subtotal( $_product, $cart_item['quantity'] ), $cart_item, $cart_item_key ); // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped ?> |
| 105 |
</td> |
| 106 |
</tr> |
| 107 |
<?php |
| 108 |
$row = ob_get_clean(); |
| 109 |
|
| 110 |
do_action( 'sellkit-block-one-page-checkout-custom-order-item', $row, $_product, $cart_item, $cart_item_key ); |
| 111 |
} |
| 112 |
} |
| 113 |
|
| 114 |
do_action( 'woocommerce_review_order_after_cart_contents' ); |
| 115 |
do_action( 'sellkit-block-checkout-custom-coupon-form' ); |
| 116 |
?> |
| 117 |
|
| 118 |
</tbody> |
| 119 |
|
| 120 |
<tfoot class="sellkit-checkout-widget-order-summary-tfoot"> |
| 121 |
<tr class="cart-subtotal"> |
| 122 |
<th class="sellkit-checkout-widget-divider"><?php esc_html_e( 'Subtotal', 'sellkit' ); ?></th> |
| 123 |
<td class="sellkit-checkout-widget-divider"><?php wc_cart_totals_subtotal_html(); ?></td> |
| 124 |
</tr> |
| 125 |
|
| 126 |
<?php do_action( 'sellkit-block-checkout-display-shipping-price' ); ?> |
| 127 |
|
| 128 |
<?php |
| 129 |
add_filter( 'woocommerce_cart_totals_coupon_label', [ $this, 'cart_totals_coupon_label' ], 10, 2 ); |
| 130 |
?> |
| 131 |
|
| 132 |
<?php foreach ( WC()->cart->get_coupons() as $code => $coupon ) : ?> |
| 133 |
<tr class="cart-discount coupon-<?php echo esc_attr( sanitize_title( $code ) ); ?>"> |
| 134 |
<th> |
| 135 |
<?php wc_cart_totals_coupon_label( $coupon ); ?> |
| 136 |
<?php |
| 137 |
$coupon = new \WC_Coupon( $coupon ); |
| 138 |
$link = esc_url( add_query_arg( 'remove_coupon', urlencode( $coupon->get_code() ), defined( 'WOOCOMMERCE_CHECKOUT' ) ? wc_get_checkout_url() : wc_get_cart_url() ) ); // phpcs:ignore |
| 139 |
?> |
| 140 |
<span |
| 141 |
class="woocommerce-remove-coupon" |
| 142 |
data-coupon="<?php echo esc_attr( $code ); ?>" |
| 143 |
data-link="<?php echo esc_attr( $link ); ?>" |
| 144 |
> |
| 145 |
<span class="woo-remove-coupon" title="<?php echo esc_attr__( 'Remove coupon', 'sellkit' ); ?>"></span> |
| 146 |
</span> |
| 147 |
</th> |
| 148 |
<td><?php wc_cart_totals_coupon_html( $coupon ); ?></td> |
| 149 |
</tr> |
| 150 |
<?php endforeach; ?> |
| 151 |
|
| 152 |
<?php /* ! shipping method moved. */ ?> |
| 153 |
|
| 154 |
<?php foreach ( WC()->cart->get_fees() as $fee ) : ?> |
| 155 |
<tr class="fee"> |
| 156 |
<th><?php echo esc_html( $fee->name ); ?></th> |
| 157 |
<td><?php wc_cart_totals_fee_html( $fee ); ?></td> |
| 158 |
</tr> |
| 159 |
<?php endforeach; ?> |
| 160 |
|
| 161 |
<?php if ( wc_tax_enabled() && ! WC()->cart->display_prices_including_tax() ) : ?> |
| 162 |
<?php if ( 'itemized' === get_option( 'woocommerce_tax_total_display' ) ) : ?> |
| 163 |
<?php foreach ( WC()->cart->get_tax_totals() as $code => $tax ) : /* phpcs:ignore */ ?> |
| 164 |
<tr class="tax-rate tax-rate-<?php echo esc_attr( sanitize_title( $code ) ); ?>"> |
| 165 |
<th><?php echo esc_html( $tax->label ); ?></th> |
| 166 |
<td><?php echo wp_kses_post( $tax->formatted_amount ); ?></td> |
| 167 |
</tr> |
| 168 |
<?php endforeach; ?> |
| 169 |
<?php else : ?> |
| 170 |
<tr class="tax-total"> |
| 171 |
<th><?php echo esc_html( WC()->countries->tax_or_vat() ); ?></th> |
| 172 |
<td><?php wc_cart_totals_taxes_total_html(); ?></td> |
| 173 |
</tr> |
| 174 |
<?php endif; ?> |
| 175 |
<?php endif; ?> |
| 176 |
|
| 177 |
<!-- Discount are hooked here --> |
| 178 |
<?php do_action( 'woocommerce_review_order_before_order_total' ); ?> |
| 179 |
|
| 180 |
<tr class="order-total"> |
| 181 |
<th class="sellkit-checkout-widget-divider sellkit-order-total"><?php esc_html_e( 'Total', 'sellkit' ); ?></th> |
| 182 |
<td class="sellkit-checkout-widget-divider sellkit-order-total"><?php wc_cart_totals_order_total_html(); ?></td> |
| 183 |
</tr> |
| 184 |
|
| 185 |
<?php do_action( 'woocommerce_review_order_after_order_total' ); ?> |
| 186 |
</tfoot> |
| 187 |
</table> |
| 188 |
</div> |
| 189 |
</div> |
| 190 |
|
| 191 |
<?php do_action( 'woocommerce_checkout_after_order_review' ); ?> |
| 192 |
|
| 193 |
<script> |
| 194 |
if ( typeof window.sellkitCheckoutMakeSureJsWorks === 'function' ) { |
| 195 |
window.sellkitCheckoutMakeSureJsWorks(); |
| 196 |
} |
| 197 |
</script> |
| 198 |
<?php if ( ! wp_doing_ajax() ) : ?> |
| 199 |
<?php do_action( 'sellkit-block-checkout-after-order-summary' ); ?> |
| 200 |
<?php endif; |
| 201 |
|
| 202 |
$final_content = ob_get_clean(); |
| 203 |
|
| 204 |
return str_replace( '</div>', $final_content . '</div>', $content ); |
| 205 |
} |
| 206 |
} |
| 207 |
|