[ $this, 'render' ], ] ); } /** * Check block has inner blocks. * * @since 2.3.0 * @return boolean */ public function has_inner_blocks() { return true; } /** * Check block has inner blocks. * * @since 2.3.0 * @return boolean */ public function get_inner_block() { $shipping_destination = get_option( 'woocommerce_ship_to_destination', true ); $inner_blocks = [ 'checkout-contact-information' => 'block-editor/blocks/checkout/inner-blocks/contact-information/class', 'checkout-form-shipping' => 'block-editor/blocks/checkout/inner-blocks/form-shipping/class', 'checkout-cart-shipping' => 'block-editor/blocks/checkout/inner-blocks/cart-shipping/class', 'checkout-review-order' => 'block-editor/blocks/checkout/inner-blocks/review-order/class', 'checkout-billing-details' => 'block-editor/blocks/checkout/inner-blocks/billing-details/class', 'checkout-payment' => 'block-editor/blocks/checkout/inner-blocks/payment/class', 'checkout-payment-continue' => 'block-editor/blocks/checkout/inner-blocks/payment-continue/class', ]; if ( 'billing_only' === $shipping_destination ) { $inner_blocks = [ 'checkout-contact-information' => 'block-editor/blocks/checkout/inner-blocks/contact-information/class', 'checkout-billing-details' => 'block-editor/blocks/checkout/inner-blocks/billing-details/class', 'checkout-cart-shipping' => 'block-editor/blocks/checkout/inner-blocks/cart-shipping/class', 'checkout-review-order' => 'block-editor/blocks/checkout/inner-blocks/review-order/class', 'checkout-payment' => 'block-editor/blocks/checkout/inner-blocks/payment/class', 'checkout-payment-continue' => 'block-editor/blocks/checkout/inner-blocks/payment-continue/class', ]; } return $inner_blocks; } /** * Clears all custom actions and filters related to SellKit checkout process. * * @since 2.3.0 */ public function clear_sellkit_checkout_custom_hooks() { remove_all_actions( 'sellkit_block_checkout_shipping_fields' ); remove_all_actions( 'sellkit_block_checkout_billing_fields' ); remove_all_actions( 'sellkit_block_checkout_after_shipping_section' ); remove_all_actions( 'sellkit-checkout-widget-express-methods' ); remove_all_actions( 'sellkit-checkout-widget-custom-coupon-form' ); remove_all_actions( 'sellkit-checkout-widget-custom-coupon-form' ); remove_all_actions( 'woocommerce_checkout_update_order_review' ); remove_all_filters( 'woocommerce_locate_template' ); } /** * Register express checkout integrations for block checkout. * * @since 2.3.0 * @return void */ private function setup_express_checkout_integrations() { sellkit()->load_files( [ 'elementor/modules/checkout/integrations/integration', 'elementor/modules/checkout/integrations/paypal-for-woocommerce', 'elementor/modules/checkout/integrations/woo-payment-gateway', 'elementor/modules/checkout/integrations/stripe-for-woocommerce', 'elementor/modules/checkout/integrations/klarma-checkout-woocommerce', 'elementor/modules/checkout/integrations/amazon-pay-woocommerce', 'elementor/modules/checkout/integrations/stripe-woocommerce-official', ] ); $gateways = [ 'Paypal_For_Woocommerce', 'Woo_Payment_Gateway', 'Stripe_For_Woocommerce', 'Klarma_Checkout_Woocommerce', 'Amazon_Pay_Woocommerce', 'Stripe_Woocommerce_Official', ]; foreach ( $gateways as $gateway ) { $class = 'Sellkit\Elementor\Modules\Checkout\Integrations\\' . $gateway; $class = new $class(); $class->run(); } } /** * Render express checkout section for block checkout. * * @param array $attributes Checkout block attributes. * @since 2.3.0 * @return string */ private function express_checkout_html( $attributes ) { if ( empty( $attributes['showExpressCheckout'] ) ) { return ''; } ob_start(); do_action( 'sellkit-checkout-widget-express-methods' ); $methods = trim( ob_get_clean() ); if ( empty( $methods ) ) { return ''; } ob_start(); ?> wp_create_nonce( 'sellkit_block_checkout' ), 'wcNeedShipping' => ( function_exists( 'WC' ) ) ? WC()->cart->needs_shipping() : '', 'url' => [ 'assets' => sellkit()->plugin_url() . 'assets/', ], ] ); } $block_html = ''; $wrapper_attributes = get_block_wrapper_attributes( [ 'class' => 'sellkit-checkout-widget-one-page-build sellkit-block-checkout-main-wrapper', ] ); do_action( 'sellkit_block_before_checkout_form' ); if ( sellkit()->has_pro ) { $this->setup_express_checkout_integrations(); $block_html .= $this->express_checkout_html( $attributes ); } foreach ( $block->inner_blocks as $inner_block ) { $block_name = str_replace( 'sellkit-inner-blocks/', '', $inner_block->parsed_block['blockName'] ); $block_name = str_replace( '-', ' ', $block_name ); $block_name = ucwords( $block_name ); $block_name = str_replace(' ', '_', $block_name ); $block_content = $inner_block->render(); $class_name = 'Sellkit\Blocks\Inner_Block\\' . ucwords( $block_name ); if ( ! class_exists( $class_name ) ) { $block_html .= $inner_block->render(); continue; } $new_class = new $class_name(); if ( method_exists( $new_class, $block_name ) ) { $block_html .= $new_class->$block_name( $block_content, $inner_block->attributes ); } } global $woocommerce; $checkout = $woocommerce->checkout; do_action( 'woocommerce_before_checkout_form', $checkout ); // If checkout registration is disabled and not logged in, the user cannot checkout. if ( ! $checkout->is_registration_enabled() && $checkout->is_registration_required() && ! is_user_logged_in() ) { echo esc_html( apply_filters( 'woocommerce_checkout_must_be_logged_in_message', esc_html__( 'You must be logged in to checkout.', 'sellkit' ) ) ); return; } $extra_class = ''; if ( WC()->cart && ! WC()->cart->needs_shipping() ) { $extra_class = 'sellkit-checkout-virtual-session'; } $block_html = sprintf( '