widgets/class-cartflows-widgets.php 0000666 00000002013 15210056463 0013500 0 ustar 00 __( 'Next Step Widgets', 'cartflows' ) ) ); } /** * Creating widget front-end * * @param array $args arguments array. * @param array $instance widget instance. */ public function widget( $args, $instance ) { $title = apply_filters( 'widget_title', $instance['title'] ); $step_id = intval( $instance['step_id'] ); $flow_id = intval( $instance['flow_id'] ); if ( ! $step_id || ! $flow_id ) { global $post; if ( $post && CARTFLOWS_STEP_POST_TYPE === $post->post_type ) { $step_id = intval( $post->ID ); $flow_id = intval( get_post_meta( $step_id, 'wcf-flow-id', true ) ); } } $output = 'No Data'; if ( $flow_id ) { $navigation = false; $steps = get_post_meta( $flow_id, 'wcf-steps', true ); if ( is_array( $steps ) && ! empty( $steps ) ) { foreach ( $steps as $i => $step ) { if ( intval( $step['id'] ) === $step_id ) { $next_i = $i + 1; if ( isset( $steps[ $next_i ] ) ) { $navigation = $steps[ $next_i ]; } break; } } if ( $navigation && is_array( $navigation ) ) { $output = '
'; } } } // before and after widget arguments are defined by themes. echo $args['before_widget']; if ( ! empty( $title ) ) { echo $args['before_title'] . $title . $args['after_title']; } // This is where you run the code and display the output. echo $output; echo $args['after_widget']; } /** * Creating widget back-end * * @param array $instance widget instance. */ public function form( $instance ) { if ( isset( $instance['title'] ) ) { $title = $instance['title']; } else { $title = __( 'New title', 'cartflows' ); } if ( isset( $instance['flow_id'] ) ) { $flow_id = $instance['flow_id']; } else { $flow_id = ''; } if ( isset( $instance['step_id'] ) ) { $step_id = $instance['step_id']; } else { $step_id = ''; } // Widget admin form. ?>
utils->get_step_post_type(), // Post_type. 'normal', // Context. 'high' // Priority. ); } } /** * Metabox Markup * * @param object $post Post object. * @return void */ public function markup_meta_box( $post ) { wp_nonce_field( 'save-nonce-checkout-step-meta', 'nonce-checkout-step-meta' ); $stored = get_post_meta( $post->ID ); $checkout_meta = self::get_meta_option( $post->ID ); // Set stored and override defaults. foreach ( $stored as $key => $value ) { if ( array_key_exists( $key, $checkout_meta ) ) { self::$meta_option[ $key ]['default'] = ( isset( $stored[ $key ][0] ) ) ? maybe_unserialize( $stored[ $key ][0] ) : ''; } else { self::$meta_option[ $key ]['default'] = ( isset( $stored[ $key ][0] ) ) ? $stored[ $key ][0] : ''; } } // Get defaults. $meta = self::get_meta_option( $post->ID ); $checkout_data = array(); foreach ( $meta as $key => $value ) { $checkout_data[ $key ] = $meta[ $key ]['default']; } /** $billing_fields = Cartflows_Helper::get_checkout_fields( 'billing', $post->ID ); // For loop foreach ( $billing_fields as $key => $value ) { $checkout_data[ 'wcf-' . $key ] = $meta[ 'wcf-' . $key ]['default']; } $shipping_fields = Cartflows_Helper::get_checkout_fields( 'shipping', $post->ID ); foreach ( $shipping_fields as $key => $value ) { $checkout_data[ 'wcf-' . $key ] = $meta[ 'wcf-' . $key ]['default']; } $additional_fields = Cartflows_Helper::get_checkout_fields( 'additional', $post->ID ); foreach ( $additional_fields as $key => $value ) { $checkout_data[ 'wcf-' . $key ] = $meta[ 'wcf-' . $key ]['default']; } */ do_action( 'wcf_checkout_settings_markup_before' ); $this->tabs_markup( $checkout_data, $post->ID ); do_action( 'wcf_checkout_settings_markup_after' ); } /** * Page Header Tabs * * @param array $options options. * @param int $post_id post ID. */ public function tabs_markup( $options, $post_id ) { $active_tab = get_post_meta( $post_id, 'wcf-active-tab', true ); if ( empty( $active_tab ) ) { $active_tab = 'wcf-checkout-shortcodes'; } $tab_array = array( array( 'title' => __( 'Shortcodes', 'cartflows' ), 'id' => 'wcf-checkout-shortcodes', 'class' => 'wcf-checkout-shortcodes' === $active_tab ? 'wcf-tab wp-ui-text-highlight active' : 'wcf-tab', 'icon' => 'dashicons-editor-code', ), array( 'title' => __( 'Select Product', 'cartflows' ), 'id' => 'wcf-checkout-general', 'class' => 'wcf-checkout-general' === $active_tab ? 'wcf-tab wp-ui-text-highlight active' : 'wcf-tab', 'icon' => 'dashicons-info', ), array( 'title' => __( 'Order Bump', 'cartflows' ), 'id' => 'wcf-product-order-bump', 'class' => 'wcf-product-order-bump' === $active_tab ? 'wcf-tab wp-ui-text-highlight active' : 'wcf-tab', 'icon' => 'dashicons-cart', ), array( 'title' => __( 'Checkout Offer', 'cartflows' ), 'id' => 'wcf-pre-checkout-offer', 'class' => 'wcf-pre-checkout-offer' === $active_tab ? 'wcf-tab wp-ui-text-highlight active' : 'wcf-tab', 'icon' => 'dashicons-arrow-up-alt', ), array( 'title' => __( 'Checkout Design', 'cartflows' ), 'id' => 'wcf-checkout-style', 'class' => 'wcf-checkout-style' === $active_tab ? 'wcf-tab wp-ui-text-highlight active' : 'wcf-tab', 'icon' => 'dashicons-admin-customizer', ), array( 'title' => __( 'Checkout Fields', 'cartflows' ), 'id' => 'wcf-checkout-custom-fields', 'class' => 'wcf-checkout-custom-fields' === $active_tab ? 'wcf-tab wp-ui-text-highlight active' : 'wcf-tab', 'icon' => 'dashicons-welcome-widgets-menus', ), array( 'title' => __( 'Checkout Settings', 'cartflows' ), 'id' => 'wcf-checkout-custom-settings', 'class' => 'wcf-checkout-custom-settings' === $active_tab ? 'wcf-tab wp-ui-text-highlight active' : 'wcf-tab', 'icon' => 'dashicons-admin-generic', ), array( 'title' => __( 'Custom Script', 'cartflows' ), 'id' => 'wcf-checkout-custom-script-header', 'class' => 'wcf-checkout-custom-script-header' === $active_tab ? 'wcf-tab wp-ui-text-highlight active' : 'wcf-tab', 'icon' => 'dashicons-format-aside', ), ); $show_logo = filter_input( INPUT_GET, 'logo-tab', FILTER_VALIDATE_BOOLEAN ); if ( $show_logo ) { $logo_tab = array( 'title' => __( 'Logo (Optional)', 'cartflows' ), 'id' => 'wcf-checkout-header', 'class' => 'wcf-checkout-header' === $active_tab ? 'wcf-tab wp-ui-text-highlight active' : 'wcf-tab', 'icon' => 'dashicons-format-image', ); array_push( $tab_array, $logo_tab ); } $tabs = apply_filters( 'cartflows_checkout_tabs', $tab_array, $active_tab ); ?>
' . __( 'WooCommerce functions do not exist. If you are in an IFrame, please reload it.', 'cartflows' ) . '
'; $notice_out .= ''; return $notice_out; } $atts = shortcode_atts( array( 'id' => 0, ), $atts ); $checkout_id = intval( $atts['id'] ); if ( empty( $checkout_id ) ) { if ( ! _is_wcf_checkout_type() ) { return '' . esc_html__( 'Variations Not set', 'cartflows' ) . '
'; } } } else { WC()->cart->add_to_cart( $product_id, $quantity ); $cart_product_count++; } } else { $wrong_product_notice = __( 'This product can\'t be purchased', 'cartflows' ); wc_add_notice( $wrong_product_notice ); /** WC()->cart->add_to_cart( $product_id, $quantity );. */ } } } /* Since 1.2.2 */ wcf_do_action_deprecated( 'cartflows_checkout_aftet_configure_cart', array( $checkout_id ), '1.2.2', 'cartflows_checkout_after_configure_cart' ); do_action( 'cartflows_checkout_after_configure_cart', $checkout_id ); } } } /** * Load shortcode data. * * @return void */ public function shortcode_load_data() { if ( _is_wcf_checkout_type() || _is_wcf_checkout_shortcode() ) { add_action( 'wp_enqueue_scripts', array( $this, 'shortcode_scripts' ), 21 ); add_action( 'wp_enqueue_scripts', array( $this, 'compatibility_scripts' ), 101 ); /* Show notices if cart has errors */ add_action( 'woocommerce_cart_has_errors', 'woocommerce_output_all_notices' ); add_action( 'woocommerce_checkout_after_customer_details', array( $this, 'order_wrap_div_start' ), 99 ); add_action( 'woocommerce_checkout_after_order_review', array( $this, 'order_wrap_div_end' ), 99 ); // Outputting the hidden field in checkout page. add_action( 'woocommerce_after_order_notes', array( $this, 'checkout_shortcode_post_id' ), 99 ); add_action( 'woocommerce_login_form_end', array( $this, 'checkout_shortcode_post_id' ), 99 ); remove_all_actions( 'woocommerce_checkout_billing' ); remove_all_actions( 'woocommerce_checkout_shipping' ); // Hook in actions once. add_action( 'woocommerce_checkout_billing', array( WC()->checkout, 'checkout_form_billing' ) ); add_action( 'woocommerce_checkout_shipping', array( WC()->checkout, 'checkout_form_shipping' ) ); remove_action( 'woocommerce_before_checkout_form', 'woocommerce_checkout_coupon_form' ); add_action( 'woocommerce_checkout_order_review', array( $this, 'display_custom_coupon_field' ) ); add_filter( 'woocommerce_checkout_fields', array( $this, 'add_three_column_layout_fields' ) ); add_filter( 'woocommerce_cart_totals_coupon_html', array( $this, 'remove_coupon_text' ) ); add_filter( 'woocommerce_order_button_text', array( $this, 'place_order_button_text' ), 10, 1 ); global $post; if ( _is_wcf_checkout_type() ) { $checkout_id = $post->ID; } else { $checkout_id = _get_wcf_checkout_id_from_shortcode( $post->post_content ); } do_action( 'cartflows_checkout_before_shortcode', $checkout_id ); } } /** * Render checkout ID hidden field. * * @param array $checkout checkout session data. * @return void */ public function checkout_shortcode_post_id( $checkout ) { global $post; if ( _is_wcf_checkout_type() ) { $checkout_id = $post->ID; } else { $checkout_id = _get_wcf_checkout_id_from_shortcode( $post->post_content ); } $flow_id = get_post_meta( $checkout_id, 'wcf-flow-id', true ); echo ''; echo ''; } /** * Load shortcode scripts. * * @return void */ public function shortcode_scripts() { wp_enqueue_style( 'wcf-checkout-template', wcf()->utils->get_css_url( 'checkout-template' ), '', CARTFLOWS_VER ); wp_enqueue_script( 'wcf-checkout-template', wcf()->utils->get_js_url( 'checkout-template' ), array( 'jquery' ), CARTFLOWS_VER, true ); do_action( 'cartflows_checkout_scripts' ); $style = $this->generate_style(); wp_add_inline_style( 'wcf-checkout-template', $style ); } /** * Load compatibility scripts. * * @return void */ public function compatibility_scripts() { global $post; if ( _is_wcf_checkout_type() ) { $checkout_id = $post->ID; } else { $checkout_id = _get_wcf_checkout_id_from_shortcode( $post->post_content ); } // Add DIVI Compatibility css if DIVI theme is enabled. if ( Cartflows_Compatibility::get_instance()->is_divi_enabled() || Cartflows_Compatibility::get_instance()->is_divi_builder_enabled( $checkout_id ) ) { wp_enqueue_style( 'wcf-checkout-template-divi', wcf()->utils->get_css_url( 'checkout-template-divi' ), '', CARTFLOWS_VER ); } // Add Flatsome Compatibility css if Flatsome theme is enabled. if ( Cartflows_Compatibility::get_instance()->is_flatsome_enabled() ) { wp_enqueue_style( 'wcf-checkout-template-flatsome', wcf()->utils->get_css_url( 'checkout-template-flatsome' ), '', CARTFLOWS_VER ); } // Add The7 Compatibility css if The7 theme is enabled. if ( Cartflows_Compatibility::get_instance()->is_the_seven_enabled() ) { wp_enqueue_style( 'wcf-checkout-template-the-seven', wcf()->utils->get_css_url( 'checkout-template-the-seven' ), '', CARTFLOWS_VER ); } } /** * Generate styles. * * @return string */ public function generate_style() { global $post; if ( _is_wcf_checkout_type() ) { $checkout_id = $post->ID; } else { $checkout_id = _get_wcf_checkout_id_from_shortcode( $post->post_content ); } /*Output css variable */ $output = ''; CartFlows_Font_Families::render_fonts( $checkout_id ); $primary_color = wcf()->options->get_checkout_meta_value( $checkout_id, 'wcf-primary-color' ); $base_font_family = wcf()->options->get_checkout_meta_value( $checkout_id, 'wcf-base-font-family' ); $header_logo_width = wcf()->options->get_checkout_meta_value( $checkout_id, 'wcf-header-logo-width' ); /** $base_font_weight = wcf()->options->get_checkout_meta_value( $checkout_id, 'wcf-base-font-weight' );*/ $r = ''; $g = ''; $b = ''; $field_tb_padding = ''; $field_lr_padding = ''; $field_heading_color = ''; $field_color = ''; $field_bg_color = ''; $field_border_color = ''; $field_label_color = ''; $submit_tb_padding = ''; $submit_lr_padding = ''; $hl_bg_color = ''; $field_input_size = ''; $box_border_color = ''; $section_bg_color = ''; $submit_button_height = ''; $submit_color = ''; $submit_bg_color = $primary_color; $submit_border_color = $primary_color; $submit_hover_color = ''; $submit_bg_hover_color = $primary_color; $submit_border_hover_color = $primary_color; $section_heading_color = ''; $is_advance_option = wcf()->options->get_checkout_meta_value( $checkout_id, 'wcf-advance-options-fields' ); $button_font_family = ''; $button_font_weight = ''; $input_font_family = ''; $input_font_weight = ''; $heading_font_family = ''; $heading_font_weight = ''; $base_font_family = $base_font_family; /** $base_font_weight = $base_font_weight;*/ if ( 'yes' == $is_advance_option ) { /** * Get Font Family and Font Weight weight values */ $section_bg_color = wcf()->options->get_checkout_meta_value( $checkout_id, 'wcf-section-bg-color' ); $heading_font_family = wcf()->options->get_checkout_meta_value( $checkout_id, 'wcf-heading-font-family' ); $heading_font_weight = wcf()->options->get_checkout_meta_value( $checkout_id, 'wcf-heading-font-weight' ); $section_heading_color = wcf()->options->get_checkout_meta_value( $checkout_id, 'wcf-heading-color' ); $button_font_family = wcf()->options->get_checkout_meta_value( $checkout_id, 'wcf-button-font-family' ); $button_font_weight = wcf()->options->get_checkout_meta_value( $checkout_id, 'wcf-button-font-weight' ); $input_font_family = wcf()->options->get_checkout_meta_value( $checkout_id, 'wcf-input-font-family' ); $input_font_weight = wcf()->options->get_checkout_meta_value( $checkout_id, 'wcf-input-font-weight' ); $field_tb_padding = wcf()->options->get_checkout_meta_value( $checkout_id, 'wcf-field-tb-padding' ); $field_lr_padding = wcf()->options->get_checkout_meta_value( $checkout_id, 'wcf-field-lr-padding' ); $field_input_size = wcf()->options->get_checkout_meta_value( $checkout_id, 'wcf-input-field-size' ); $field_heading_color = wcf()->options->get_checkout_meta_value( $checkout_id, 'wcf-field-heading-color' ); $field_color = wcf()->options->get_checkout_meta_value( $checkout_id, 'wcf-field-color' ); $field_bg_color = wcf()->options->get_checkout_meta_value( $checkout_id, 'wcf-field-bg-color' ); $field_border_color = wcf()->options->get_checkout_meta_value( $checkout_id, 'wcf-field-border-color' ); $field_label_color = wcf()->options->get_checkout_meta_value( $checkout_id, 'wcf-field-label-color' ); $submit_tb_padding = wcf()->options->get_checkout_meta_value( $checkout_id, 'wcf-submit-tb-padding' ); $submit_lr_padding = wcf()->options->get_checkout_meta_value( $checkout_id, 'wcf-submit-lr-padding' ); $submit_color = wcf()->options->get_checkout_meta_value( $checkout_id, 'wcf-submit-color' ); $submit_bg_color = wcf()->options->get_checkout_meta_value( $checkout_id, 'wcf-submit-bg-color', $primary_color ); $submit_border_color = wcf()->options->get_checkout_meta_value( $checkout_id, 'wcf-submit-border-color', $primary_color ); $submit_border_hover_color = wcf()->options->get_checkout_meta_value( $checkout_id, 'wcf-submit-border-hover-color', $primary_color ); $submit_hover_color = wcf()->options->get_checkout_meta_value( $checkout_id, 'wcf-submit-hover-color' ); $submit_bg_hover_color = wcf()->options->get_checkout_meta_value( $checkout_id, 'wcf-submit-bg-hover-color', $primary_color ); $hl_bg_color = wcf()->options->get_checkout_meta_value( $checkout_id, 'wcf-hl-bg-color' ); $box_border_color = wcf()->options->get_checkout_meta_value( $checkout_id, 'wcf-box-border-color' ); $submit_button_height = wcf()->options->get_checkout_meta_value( $checkout_id, 'wcf-input-button-size' ); /** * Get font values */ if ( 'custom' == $submit_button_height ) { $submit_button_height = '38px'; } if ( 'custom' == $field_input_size ) { $field_input_size = '38px'; } } if ( isset( $primary_color ) ) { list($r, $g, $b) = sscanf( $primary_color, '#%02x%02x%02x' ); } if ( Cartflows_Compatibility::get_instance()->is_divi_enabled() || Cartflows_Compatibility::get_instance()->is_divi_builder_enabled( $checkout_id ) ) { include CARTFLOWS_CHECKOUT_DIR . 'includes/checkout-dynamic-divi-css.php'; } else { include CARTFLOWS_CHECKOUT_DIR . 'includes/checkout-dynamic-css.php'; } return $output; } /** * Get ajax end points. * * @param string $endpoint_url end point URL. * @param string $request end point request. * @return string */ public function get_ajax_endpoint( $endpoint_url, $request ) { global $post; if ( ! empty( $post ) && ! empty( $_SERVER['REQUEST_URI'] ) ) { if ( _is_wcf_checkout_type() ) { if ( mb_strpos( $endpoint_url, 'checkout', 0, 'utf-8' ) === false ) { if ( '' === $request ) { $query_args = array( 'wc-ajax' => '%%endpoint%%', ); } else { $query_args = array( 'wc-ajax' => $request, ); } $uri = explode( '?', $_SERVER['REQUEST_URI'], 2 ); //phpcs:ignore $uri = $uri[0]; $endpoint_url = esc_url( add_query_arg( $query_args, $uri ) ); } } } return $endpoint_url; } /** * Save checkout fields. * * @param int $order_id order id. * @param array $posted posted data. * @return void */ public function save_checkout_fields( $order_id, $posted ) { if ( isset( $_POST['_wcf_checkout_id'] ) ) { //phpcs:ignore $checkout_id = wc_clean( intval( $_POST['_wcf_checkout_id'] ) ); //phpcs:ignore update_post_meta( $order_id, '_wcf_checkout_id', $checkout_id ); if ( isset( $_POST['_wcf_flow_id'] ) ) { //phpcs:ignore $flow_id = wc_clean( intval( $_POST['_wcf_flow_id'] ) ); //phpcs:ignore update_post_meta( $order_id, '_wcf_flow_id', $flow_id ); } } } /** * Enable Logo In Header Of Checkout Page * * @return void */ public function enable_logo_in_header() { global $post; if ( _is_wcf_checkout_type() ) { $checkout_id = $post->ID; } else { $checkout_id = _get_wcf_checkout_id_from_shortcode( $post->post_content ); } $header_logo_image = wcf()->options->get_checkout_meta_value( $checkout_id, 'wcf-header-logo-image' ); $add_image_markup = ''; if ( isset( $header_logo_image ) && ! empty( $header_logo_image ) ) { $add_image_markup = '' . __( 'WooCommerce functions do not exist. If you are in an IFrame, please reload it.', 'cartflows' ) . '
'; $notice_out .= ''; return $notice_out; } $atts = shortcode_atts( array( 'id' => 0, ), $atts ); $optin_id = intval( $atts['id'] ); if ( empty( $optin_id ) ) { if ( ! _is_wcf_optin_type() ) { return '' . sprintf( esc_html__( 'Upgrade to %1$sCartFlows Pro%2$s for Analytics feature', 'cartflows' ), '', '' ) . '
'; echo ''; echo '' . __( 'WooCommerce functions do not exist. If you are in an IFrame, please reload it.', 'cartflows' ) . '
'; $notice_out .= ''; return $notice_out; } $order = false; $id_param = 'wcf-order'; $key_param = 'wcf-key'; if ( isset( $_GET['wcf-opt-order'] ) ) { //phpcs:ignore $id_param = 'wcf-opt-order'; $key_param = 'wcf-opt-key'; } if ( ! isset( $_GET[ $id_param ] ) && wcf()->flow->is_flow_testmode() ) { //phpcs:ignore $args = array( 'limit' => 1, 'order' => 'DESC', 'post_type' => 'shop_order', 'status' => array( 'completed', 'processing' ), ); $latest_order = wc_get_orders( $args ); $order_id = ( ! empty( $latest_order ) ) ? current( $latest_order )->get_id() : 0; if ( $order_id > 0 ) { $order = wc_get_order( $order_id ); if ( ! $order ) { $order = false; } } } else { if ( ! isset( $_GET[ $id_param ] ) ) { //phpcs:ignore return 'Order not found. You cannot access this page directly.
'; } // Get the order. $order_id = apply_filters( 'woocommerce_thankyou_order_id', empty( $_GET[ $id_param ] ) ? 0 : intval( $_GET[ $id_param ] ) ); //phpcs:ignore $order_key = apply_filters( 'woocommerce_thankyou_order_key', empty( $_GET[ $key_param ] ) ? '' : wc_clean( wp_unslash( $_GET[ $key_param ] ) ) ); //phpcs:ignore if ( $order_id > 0 ) { $order = wc_get_order( $order_id ); if ( ! $order || $order->get_order_key() !== $order_key ) { $order = false; } } } // Empty awaiting payment session. unset( WC()->session->order_awaiting_payment ); if ( null !== WC()->session ) { if ( ! isset( WC()->cart ) || '' === WC()->cart ) { WC()->cart = new WC_Cart(); } if ( ! WC()->cart->is_empty() ) { // wc_empty_cart(); // Empty current cart. WC()->cart->empty_cart( true ); wc_clear_notices(); } wc_print_notices(); } ob_start(); echo "