widgets/class-cartflows-widgets.php000066600000002013152100564630013500 0ustar00 __( '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 = '
' . __( 'Next Step', 'cartflows' ) . '
'; } } } // 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 ); ?>
$tab ) { ?>
tab_shortcodes( $options, $post_id ); ?> tab_general( $options, $post_id ); ?> tab_style( $options, $post_id ); ?> tab_pre_checkout_offer( $options, $post_id ); ?> tab_product_bump( $options, $post_id ); ?> tab_custom_fields( $options, $post_id ); ?> tab_custom_settings( $options, $post_id ); ?> tab_header_content( $options, $post_id ); ?> tab_custom_script( $options, $post_id ); ?> right_column_footer( $options, $post_id ); ?>
meta->get_shortcode_field( array( 'label' => 'Checkout Page', 'name' => 'wcf-checkout-shortcode', 'content' => '[cartflows_checkout]', 'help' => esc_html__( 'Add this shortcode to your checkout page', 'cartflows' ), ) ); ?>
meta->get_product_selection_repeater( array( 'name' => 'wcf-checkout-products', 'value' => $options['wcf-checkout-products'], 'allow_clear' => true, ) ); if ( ! _is_cartflows_pro() ) { echo wcf()->meta->get_hr_line_field( array() ); echo wcf()->meta->get_description_field( array( 'name' => 'wcf-upgrade-to-pro', /* translators: %s: link */ 'content' => '' . sprintf( esc_html__( 'Upgrade to %1$sCartFlows Pro%2$s for Pre-applied Coupon, Product Variations & Quantity Options.', 'cartflows' ), '', '' ) . '', ) ); } do_action( 'cartflows_checkout_general_tab_content', $options, $post_id ); ?>
meta->get_description_field( array( 'name' => 'wcf-upgrade-to-pro', /* translators: %s: link */ 'content' => '' . sprintf( esc_html__( 'Upgrade to %1$sCartFlows Pro%2$s for Checkout Offer feature', 'cartflows' ), '', '' ) . '', ) ); } elseif ( _is_cartflows_pro_ver_less_than( '1.2.0' ) ) { $version = '1.2.0'; echo wcf()->meta->get_description_field( array( 'name' => 'wcf-upgrade-to-pro', /* translators: %s: link */ 'content' => '' . sprintf( esc_html__( 'Update to %1$sCartFlows Pro%2$s to %3$s or above for Checkout Offer feature', 'cartflows' ), '', '', $version ) . '', ) ); } ?>
meta->get_hr_line_field( array() ); if ( ! _is_cartflows_pro() ) { echo wcf()->meta->get_description_field( array( 'name' => 'wcf-upgrade-to-pro', /* translators: %s: link */ 'content' => '' . sprintf( __( 'Upgrade to %1$sCartFlows Pro%2$s for animate browser tab feature', 'cartflows' ), '', '' ) . '', ) ); } elseif ( _is_cartflows_pro_ver_less_than( '1.4.0' ) ) { $version = '1.4.0'; echo wcf()->meta->get_description_field( array( 'name' => 'wcf-upgrade-to-pro', /* translators: %s: link */ 'content' => '' . sprintf( __( 'Update to %1$sCartFlows Pro%2$s to %3$s or above for animate browser tab feature', 'cartflows' ), '', '', $version ) . '', ) ); } do_action( 'cartflows_animate_browser_tab_settings', $options, $post_id ); } /** * Product bump tab * * @param array $options options. * @param int $post_id post ID. */ public function tab_product_bump( $options, $post_id ) { ?>
meta->get_description_field( array( 'name' => 'wcf-upgrade-to-pro', /* translators: %s: link */ 'content' => '' . sprintf( esc_html__( 'Upgrade to %1$sCartFlows Pro%2$s for Order Bump feature.', 'cartflows' ), '', '' ) . '', ) ); } ?>
meta->get_description_field( array( 'name' => 'wcf-upgrade-to-pro', /* translators: %s: link */ 'content' => '' . sprintf( esc_html__( 'Upgrade to %1$sCartFlows Pro%2$s for Custom Fields feature.', 'cartflows' ), '', '' ) . '', ) ); } ?>
meta->get_text_field( array( 'label' => __( 'Place Order Button Text', 'cartflows' ), 'name' => 'wcf-checkout-place-order-button-text', 'value' => $options['wcf-checkout-place-order-button-text'], 'attr' => array( 'placeholder' => __( 'Place order', 'cartflows' ), ), 'help' => __( 'It will change the Place Order Button text on checkout page.', 'cartflows' ), ) ); echo wcf()->meta->get_hr_line_field( array() ); echo wcf()->meta->get_checkbox_field( array( 'name' => 'wcf-remove-product-field', 'value' => $options['wcf-remove-product-field'], 'after' => esc_html__( 'Enable cart editing on checkout', 'cartflows' ), ) ); echo wcf()->meta->get_description_field( array( 'name' => '', /* translators: %s: link */ 'content' => '' . sprintf( esc_html__( 'Users will able to remove products from the checkout page.', 'cartflows' ), '', '' ) . '', ) ); $this->animate_title_settings( $options, $post_id ); ?>
__( 'One Column (Available in CartFlows Pro) ', 'cartflows' ), 'two-step' => __( 'Two Step (Available in CartFlows Pro) ', 'cartflows' ), ); } echo wcf()->meta->get_select_field( array( 'label' => __( 'Checkout Skin', 'cartflows' ), 'name' => 'wcf-checkout-layout', 'value' => $options['wcf-checkout-layout'], 'options' => array( 'one-column' => esc_html__( 'One Column', 'cartflows' ), 'two-column' => esc_html__( 'Two Column', 'cartflows' ), 'two-step' => esc_html__( 'Two Step', 'cartflows' ), ), 'pro-options' => $layout_pro_option, ) ); echo wcf()->meta->get_color_picker_field( array( 'label' => __( 'Primary Color', 'cartflows' ), 'name' => 'wcf-primary-color', 'value' => $options['wcf-primary-color'], ) ); echo wcf()->meta->get_font_family_field( array( 'for' => 'wcf-base', 'label' => esc_html__( 'Font Family', 'cartflows' ), 'name' => 'wcf-base-font-family', 'value' => $options['wcf-base-font-family'], ) ); echo wcf()->meta->get_checkbox_field( array( 'label' => __( 'Advance Options', 'cartflows' ), 'name' => 'wcf-advance-options-fields', 'value' => $options['wcf-advance-options-fields'], 'after' => 'Enable', ) ); ?>
meta->get_section( array( 'label' => __( 'Heading', 'cartflows' ), ) ); echo wcf()->meta->get_color_picker_field( array( 'label' => __( 'Heading Color', 'cartflows' ), 'name' => 'wcf-heading-color', 'value' => $options['wcf-heading-color'], ) ); echo wcf()->meta->get_font_family_field( array( 'for' => 'wcf-heading', 'label' => esc_html__( 'Font Family', 'cartflows' ), 'name' => 'wcf-heading-font-family', 'value' => $options['wcf-heading-font-family'], ) ); echo wcf()->meta->get_font_weight_field( array( 'for' => 'wcf-heading', 'label' => esc_html__( 'Font Weight', 'cartflows' ), 'name' => 'wcf-heading-font-weight', 'value' => $options['wcf-heading-font-weight'], ) ); echo wcf()->meta->get_section( array( 'label' => __( 'Input Fields', 'cartflows' ), ) ); $fields_skin_pro_option = array(); if ( ! _is_cartflows_pro() ) { $fields_skin_pro_option = array( 'style-one' => __( 'Floating Labels (Available in CartFlows Pro)', 'cartflows' ), ); } echo wcf()->meta->get_select_field( array( 'label' => __( 'Style', 'cartflows' ), 'name' => 'wcf-fields-skins', 'value' => $options['wcf-fields-skins'], 'options' => array( 'default' => esc_html__( 'Default', 'cartflows' ), 'style-one' => esc_html__( 'Floating Labels', 'cartflows' ), ), 'pro-options' => $fields_skin_pro_option, ) ); echo wcf()->meta->get_font_family_field( array( 'for' => 'wcf-input', 'label' => esc_html__( 'Font Family', 'cartflows' ), 'name' => 'wcf-input-font-family', 'value' => $options['wcf-input-font-family'], ) ); echo wcf()->meta->get_font_weight_field( array( 'for' => 'wcf-input', 'label' => esc_html__( 'Font Weight', 'cartflows' ), 'name' => 'wcf-input-font-weight', 'value' => $options['wcf-input-font-weight'], ) ); echo wcf()->meta->get_select_field( array( 'label' => __( 'Size', 'cartflows' ), 'name' => 'wcf-input-field-size', 'value' => $options['wcf-input-field-size'], 'options' => array( '33px' => esc_html__( 'Extra Small', 'cartflows' ), '38px' => esc_html__( 'Small', 'cartflows' ), '44px' => esc_html__( 'Medium', 'cartflows' ), '58px' => esc_html__( 'Large', 'cartflows' ), '68px' => esc_html__( 'Extra Large', 'cartflows' ), 'custom' => esc_html__( 'Custom', 'cartflows' ), ), ) ); echo wcf()->meta->get_number_field( array( 'label' => __( 'Top Bottom Spacing', 'cartflows' ), 'name' => 'wcf-field-tb-padding', 'value' => $options['wcf-field-tb-padding'], ) ); echo wcf()->meta->get_number_field( array( 'label' => __( 'Left Right Spacing', 'cartflows' ), 'name' => 'wcf-field-lr-padding', 'value' => $options['wcf-field-lr-padding'], ) ); echo wcf()->meta->get_color_picker_field( array( 'label' => __( 'Text / Placeholder Color', 'cartflows' ), 'name' => 'wcf-field-color', 'value' => $options['wcf-field-color'], ) ); echo wcf()->meta->get_color_picker_field( array( 'label' => __( 'Background Color', 'cartflows' ), 'name' => 'wcf-field-bg-color', 'value' => $options['wcf-field-bg-color'], ) ); echo wcf()->meta->get_color_picker_field( array( 'label' => __( 'Border Color', 'cartflows' ), 'name' => 'wcf-field-border-color', 'value' => $options['wcf-field-border-color'], ) ); echo wcf()->meta->get_color_picker_field( array( 'label' => __( 'Label Color', 'cartflows' ), 'name' => 'wcf-field-label-color', 'value' => $options['wcf-field-label-color'], ) ); ?>
meta->get_section( array( 'label' => __( 'Buttons', 'cartflows' ), ) ); echo wcf()->meta->get_font_family_field( array( 'for' => 'wcf-button', 'label' => esc_html__( 'Font Family', 'cartflows' ), 'name' => 'wcf-button-font-family', 'value' => $options['wcf-button-font-family'], ) ); echo wcf()->meta->get_font_weight_field( array( 'for' => 'wcf-button', 'label' => esc_html__( 'Font Weight', 'cartflows' ), 'name' => 'wcf-button-font-weight', 'value' => $options['wcf-button-font-weight'], ) ); echo wcf()->meta->get_select_field( array( 'label' => __( 'Size', 'cartflows' ), 'name' => 'wcf-input-button-size', 'value' => $options['wcf-input-button-size'], 'options' => array( '33px' => esc_html__( 'Extra Small', 'cartflows' ), '38px' => esc_html__( 'Small', 'cartflows' ), '44px' => esc_html__( 'Medium', 'cartflows' ), '58px' => esc_html__( 'Large', 'cartflows' ), '68px' => esc_html__( 'Extra Large', 'cartflows' ), 'custom' => esc_html__( 'Custom', 'cartflows' ), ), ) ); echo wcf()->meta->get_number_field( array( 'label' => __( 'Top Bottom Spacing', 'cartflows' ), 'name' => 'wcf-submit-tb-padding', 'value' => $options['wcf-submit-tb-padding'], ) ); echo wcf()->meta->get_number_field( array( 'label' => __( 'Left Right Spacing', 'cartflows' ), 'name' => 'wcf-submit-lr-padding', 'value' => $options['wcf-submit-lr-padding'], ) ); echo wcf()->meta->get_color_picker_field( array( 'label' => __( 'Text Color', 'cartflows' ), 'name' => 'wcf-submit-color', 'value' => $options['wcf-submit-color'], ) ); echo wcf()->meta->get_color_picker_field( array( 'label' => __( 'Text Hover Color', 'cartflows' ), 'name' => 'wcf-submit-hover-color', 'value' => $options['wcf-submit-hover-color'], ) ); echo wcf()->meta->get_color_picker_field( array( 'label' => __( 'Background Color', 'cartflows' ), 'name' => 'wcf-submit-bg-color', 'value' => $options['wcf-submit-bg-color'], ) ); echo wcf()->meta->get_color_picker_field( array( 'label' => __( 'Background Hover Color', 'cartflows' ), 'name' => 'wcf-submit-bg-hover-color', 'value' => $options['wcf-submit-bg-hover-color'], ) ); echo wcf()->meta->get_color_picker_field( array( 'label' => __( 'Border Color', 'cartflows' ), 'name' => 'wcf-submit-border-color', 'value' => $options['wcf-submit-border-color'], ) ); echo wcf()->meta->get_color_picker_field( array( 'label' => __( 'Border Hover Color', 'cartflows' ), 'name' => 'wcf-submit-border-hover-color', 'value' => $options['wcf-submit-border-hover-color'], ) ); ?>
meta->get_section( array( 'label' => __( 'Sections', 'cartflows' ), ) ); echo wcf()->meta->get_color_picker_field( array( 'label' => __( 'Highlight Area Background Color', 'cartflows' ), 'name' => 'wcf-hl-bg-color', 'value' => $options['wcf-hl-bg-color'], ) ); echo wcf()->meta->get_hidden_field( array( 'name' => 'wcf-field-google-font-url', 'value' => $options['wcf-field-google-font-url'], ) ); ?>
meta->get_image_field( array( 'name' => 'wcf-header-logo-image', 'value' => $options['wcf-header-logo-image'], 'label' => esc_html__( 'Header Logo', 'cartflows' ), ) ); echo wcf()->meta->get_number_field( array( 'name' => 'wcf-header-logo-width', 'value' => $options['wcf-header-logo-width'], 'label' => esc_html__( 'Logo Width (In px)', 'cartflows' ), ) ); ?>
options->get_checkout_fields( $post_id ); } return self::$meta_option; } /** * Metabox Save * * @param number $post_id Post ID. * @return void */ public function save_meta_box( $post_id ) { // Checks save status. $is_autosave = wp_is_post_autosave( $post_id ); $is_revision = wp_is_post_revision( $post_id ); $is_valid_nonce = ( isset( $_POST['nonce-checkout-step-meta'] ) && wp_verify_nonce( sanitize_text_field( wp_unslash( $_POST['nonce-checkout-step-meta'] ) ), 'save-nonce-checkout-step-meta' ) ) ? true : false; // Exits script depending on save status. if ( $is_autosave || $is_revision || ! $is_valid_nonce ) { return; } wcf()->options->save_checkout_fields( $post_id ); } } /** * Kicking this off by calling 'get_instance()' method */ Cartflows_Checkout_Meta::get_instance(); checkout/classes/class-cartflows-checkout-markup.php000066600000102541152100564630016737 0ustar00utils->get_checkout_id_from_post_data(); if ( ! $checkout_id ) { return $args; } // Set cancel return URL. $args['cancel_return'] = esc_url_raw( $order->get_cancel_order_url_raw( get_permalink( $checkout_id ) ) ); return $args; } /** * Modify WooCommerce paypal arguments. * * @param string $product_name product name. * @param object $cart_item cart item. * @param string $cart_item_key cart item key. * @return string */ public function wcf_add_remove_label( $product_name, $cart_item, $cart_item_key ) { $checkout_id = get_the_ID(); if ( ! $checkout_id ) { $checkout_id = ( isset( $_POST['option']['checkout_id'] ) ) ? wp_unslash( $_POST['option']['checkout_id'] ) : '';//phpcs:ignore } if ( ! empty( $checkout_id ) ) { $is_remove_product_option = wcf()->options->get_checkout_meta_value( $checkout_id, 'wcf-remove-product-field' ); if ( 'checkout' === get_post_meta( $checkout_id, 'wcf-step-type', true ) && ( 'yes' === $is_remove_product_option ) ) { $remove_label = apply_filters( 'woocommerce_cart_item_remove_link', sprintf( '', esc_attr( $cart_item['product_id'] ), $cart_item_key ), $cart_item_key ); $product_name = $remove_label . $product_name; } } return $product_name; } /** * Change order button text . * * @param string $woo_button_text place order. * @return string */ public function place_order_button_text( $woo_button_text ) { $checkout_id = get_the_ID(); if ( ! $checkout_id ) { $checkout_id = ( isset( $_POST['option']['checkout_id'] ) ) ? intval( $_POST['option']['checkout_id'] ) : 0; //phpcs:ignore } $wcf_order_button_text = wcf()->options->get_checkout_meta_value( $checkout_id, 'wcf-checkout-place-order-button-text' ); if ( ! empty( $wcf_order_button_text ) ) { $woo_button_text = $wcf_order_button_text; } return $woo_button_text; } /** * Display all WooCommerce notices. * * @since 1.1.5 */ public function display_woo_notices() { if ( null != WC()->session && function_exists( 'woocommerce_output_all_notices' ) ) { woocommerce_output_all_notices(); } } /** * Redirect from default to the global checkout page * * @since 1.0.0 */ public function global_checkout_template_redirect() { if ( ! is_checkout() ) { return; } if ( wcf()->utils->is_step_post_type() ) { return; } // Return if the key OR Order paramater is found in the URL for certain Payment gateways. if ( isset( $_GET['key'] ) || isset( $_GET['order'] ) ) { //phpcs:ignore return; } // redirect only for cartflows checkout pages. $order_pay_endpoint = get_option( 'woocommerce_checkout_pay_endpoint', 'order-pay' ); $order_received_endpoint = get_option( 'woocommerce_checkout_order_received_endpoint', 'order-received' ); $common = Cartflows_Helper::get_common_settings(); $global_checkout = $common['global_checkout']; if ( isset( $_SERVER['REQUEST_URI'] ) && // ignore on order-pay. false === wcf_mb_strpos( esc_url_raw( wp_unslash( $_SERVER['REQUEST_URI'] ) ), '/' . $order_pay_endpoint . '/' ) && // ignore on TY page. false === wcf_mb_strpos( esc_url_raw( wp_unslash( $_SERVER['REQUEST_URI'] ) ), '/' . $order_received_endpoint . '/' ) && // ignore if order-pay in query param. false === wcf_mb_strpos( esc_url_raw( wp_unslash( $_SERVER['REQUEST_URI'] ) ), $order_pay_endpoint . '=' ) ) { if ( '' !== $global_checkout ) { $link = apply_filters( 'cartflows_global_checkout_url', get_permalink( $global_checkout ) ); if ( ! empty( $link ) ) { wp_safe_redirect( $link ); die(); } } } } /** * Check for checkout flag * * @param bool $is_checkout is checkout. * * @return bool */ public function woo_checkout_flag( $is_checkout ) { if ( ! is_admin() ) { if ( _is_wcf_checkout_type() || _is_wcf_checkout_shortcode() ) { $is_checkout = true; } } return $is_checkout; } /** * Render checkout shortcode markup. * * @param array $atts attributes. * @return string */ public function checkout_shortcode_markup( $atts ) { if ( ! function_exists( 'wc_print_notices' ) ) { $notice_out = '

' . __( '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 '

' . __( 'Checkout ID not found', 'cartflows' ) . '

'; } global $post; $checkout_id = intval( $post->ID ); } $output = ''; ob_start(); do_action( 'cartflows_checkout_form_before', $checkout_id ); $checkout_layout = wcf()->options->get_checkout_meta_value( $checkout_id, 'wcf-checkout-layout' ); $template_default = CARTFLOWS_CHECKOUT_DIR . 'templates/embed/checkout-template-simple.php'; $template_layout = apply_filters( 'cartflows_checkout_layout_template', $checkout_layout ); if ( file_exists( $template_layout ) ) { include $template_layout; } else { include $template_default; } $output .= ob_get_clean(); return $output; } /** * Configure Cart Data. * * @since 1.0.0 * * @return void */ public function preconfigured_cart_data() { if ( is_admin() ) { return; } global $post; if ( _is_wcf_checkout_type() || _is_wcf_checkout_shortcode() ) { if ( wp_doing_ajax() ) { return; } else { if ( _is_wcf_checkout_type() ) { $checkout_id = $post->ID; } else { $checkout_id = _get_wcf_checkout_id_from_shortcode( $post->post_content ); } $global_checkout = intval( Cartflows_Helper::get_common_setting( 'global_checkout' ) ); if ( ! empty( $global_checkout ) && $checkout_id === $global_checkout ) { if ( WC()->cart->is_empty() ) { wc_add_notice( __( 'Your cart is currently empty.', 'cartflows' ), 'error' ); } return; } if ( apply_filters( 'cartflows_skip_configure_cart', false, $checkout_id ) ) { return; } do_action( 'cartflows_checkout_before_configure_cart', $checkout_id ); $flow_id = wcf()->utils->get_flow_id_from_step_id( $checkout_id ); if ( wcf()->flow->is_flow_testmode( $flow_id ) ) { $products = wcf()->options->get_checkout_meta_value( $checkout_id, 'wcf-checkout-products', 'dummy' ); } else { $products = wcf()->options->get_checkout_meta_value( $checkout_id, 'wcf-checkout-products' ); } if ( ! is_array( $products ) ) { if ( 'dummy' === $products ) { $args = array( 'posts_per_page' => 1, 'orderby' => 'rand', 'post_type' => 'product', 'meta_query' => array( //phpcs:ignore // Exclude out of stock products. array( 'key' => '_stock_status', 'value' => 'outofstock', 'compare' => 'NOT IN', ), ), 'tax_query' => array( //phpcs:ignore array( 'taxonomy' => 'product_type', 'field' => 'slug', 'terms' => 'simple', ), ), ); $random_product = get_posts( $args ); if ( isset( $random_product[0]->ID ) ) { $products = array( array( 'product' => $random_product[0]->ID, ), ); } else { return; } } else { return; } } /* Empty the current cart */ WC()->cart->empty_cart(); if ( is_array( $products ) && count( $products ) < 1 ) { wc_add_notice( __( 'No product is selected. Please select products from the checkout meta settings to continue.', 'cartflows' ), 'error' ); return; } /* Set customer session if not set */ if ( ! is_user_logged_in() && WC()->cart->is_empty() ) { WC()->session->set_customer_session_cookie( true ); } $cart_product_count = 0; foreach ( $products as $index => $data ) { if ( ! isset( $data['product'] ) ) { return; } if ( apply_filters( 'cartflows_skip_other_products', false, $cart_product_count ) ) { break; } $product_id = $data['product']; $_product = wc_get_product( $product_id ); if ( ! empty( $_product ) ) { $quantity = 1; if ( ! $_product->is_type( 'grouped' ) && ! $_product->is_type( 'external' ) ) { if ( $_product->is_type( 'variable' ) ) { $default_attributes = $_product->get_default_attributes(); if ( ! empty( $default_attributes ) ) { foreach ( $_product->get_children() as $variation_id ) { $single_variation = new WC_Product_Variation( $variation_id ); if ( $default_attributes == $single_variation->get_attributes() ) { WC()->cart->add_to_cart( $variation_id, $quantity ); $cart_product_count++; } } } else { $product_childrens = $_product->get_children(); if ( isset( $product_childrens[0] ) ) { WC()->cart->add_to_cart( $product_childrens[0], $quantity ); $cart_product_count++; } else { echo '

' . 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 = '
'; $add_image_markup .= ''; $add_image_markup .= '
'; } echo $add_image_markup; } /** * Add text to the bootom of the checkout page. * * @return void */ public function show_cartflows_copyright_message() { $output_string = ''; $output_string .= ''; echo $output_string; } /** * Redirect users to our checkout if hidden param * * @param string $redirect redirect url. * @param object $user user. * @return string */ public function after_login_redirect( $redirect, $user ) { if ( isset( $_POST['_wcf_checkout_id'] ) ) { //phpcs:ignore $checkout_id = intval( $_POST['_wcf_checkout_id'] ); //phpcs:ignore $redirect = get_permalink( $checkout_id ); } return $redirect; } /** * Display coupon code field after review order fields. */ public function display_custom_coupon_field() { $coupon_enabled = apply_filters( 'woocommerce_coupons_enabled', true ); $show_coupon = apply_filters( 'cartflows_show_coupon_field', true ); if ( ! ( $coupon_enabled && $show_coupon ) ) { return; } $coupon_field = array( 'field_text' => __( 'Coupon Code', 'cartflows' ), 'button_text' => __( 'Apply', 'cartflows' ), 'class' => '', ); $coupon_field = apply_filters( 'cartflows_coupon_field_options', $coupon_field ); ob_start(); ?>
cart->add_discount( sanitize_text_field( wp_unslash( $_POST['coupon_code'] ) ) ); } else { wc_add_notice( WC_Coupon::get_generic_coupon_error( WC_Coupon::E_WC_COUPON_PLEASE_ENTER ), 'error' ); } $response = array( 'status' => $result, 'msg' => wc_print_notices( true ), ); echo wp_json_encode( $response ); die(); } /** * Added ajax nonce to localize variable. * * @param array $vars localize variables. */ public function add_localize_vars( $vars ) { $vars['wcf_validate_coupon_nonce'] = wp_create_nonce( 'wcf-apply-coupon' ); $vars['wcf_validate_remove_coupon_nonce'] = wp_create_nonce( 'wcf-remove-coupon' ); $vars['wcf_validate_remove_cart_product_nonce'] = wp_create_nonce( 'wcf-remove-cart-product' ); $vars['allow_persistance'] = apply_filters( 'cartflows_allow_persistace', 'yes' ); return $vars; } /** * Add custom class to the fields to change the UI to three column. * * @param array $fields fields. */ public function add_three_column_layout_fields( $fields ) { if ( empty( $fields['billing']['billing_address_2'] ) ) { if ( isset( $fields['billing']['billing_address_1'] ) && is_array( $fields['billing']['billing_address_1'] ) ) { $fields['billing']['billing_address_1']['class'][] = 'form-row-full'; } } if ( ! empty( $fields['billing']['billing_company'] ) ) { if ( isset( $fields['billing']['billing_company'] ) && is_array( $fields['billing']['billing_company'] ) ) { $fields['billing']['billing_company']['class'][] = 'form-row-full'; } } if ( ! empty( $fields['shipping']['shipping_company'] ) ) { if ( isset( $fields['shipping']['shipping_company'] ) && is_array( $fields['shipping']['shipping_company'] ) ) { $fields['shipping']['shipping_company']['class'][] = 'form-row-full'; } } if ( ! empty( $fields['billing']['billing_country'] ) ) { if ( isset( $fields['billing']['billing_country'] ) && is_array( $fields['billing']['billing_country'] ) ) { $fields['billing']['billing_country']['class'][] = 'form-row-full'; } } if ( ! empty( $fields['shipping']['shipping_country'] ) ) { if ( isset( $fields['shipping']['shipping_country'] ) && is_array( $fields['shipping']['shipping_country'] ) ) { $fields['shipping']['shipping_country']['class'][] = 'form-row-full'; } } if ( ! empty( $fields['billing']['billing_phone'] ) ) { if ( isset( $fields['billing']['billing_phone'] ) && is_array( $fields['billing']['billing_phone'] ) ) { $fields['billing']['billing_phone']['class'][] = 'form-row-full'; } } if ( ! empty( $fields['billing']['billing_email'] ) ) { if ( isset( $fields['billing']['billing_email'] ) && is_array( $fields['billing']['billing_email'] ) ) { $fields['billing']['billing_email']['class'][] = 'form-row-full'; } } if ( empty( $fields['shipping']['shipping_address_2'] ) ) { if ( isset( $fields['shipping']['shipping_address_1'] ) && is_array( $fields['shipping']['shipping_address_1'] ) ) { $fields['shipping']['shipping_address_1']['class'][] = 'form-row-full'; } } if ( isset( $fields['billing']['billing_city'] ) && isset( $fields['billing']['billing_state'] ) && isset( $fields['billing']['billing_postcode'] ) ) { $fields['billing']['billing_city']['class'][] = 'wcf-column-33'; $fields['billing']['billing_state']['class'][] = 'wcf-column-33'; $fields['billing']['billing_postcode']['class'][] = 'wcf-column-33'; } if ( isset( $fields['shipping']['shipping_city'] ) && isset( $fields['shipping']['shipping_state'] ) && isset( $fields['shipping']['shipping_postcode'] ) ) { $fields['shipping']['shipping_city']['class'][] = 'wcf-column-33'; $fields['shipping']['shipping_state']['class'][] = 'wcf-column-33'; $fields['shipping']['shipping_postcode']['class'][] = 'wcf-column-33'; } return $fields; } /** * Add opening dev * * @since 1.0.0 */ public function order_wrap_div_start() { echo "
"; } /** * Add closing dev * * @since 1.0.0 */ public function order_wrap_div_end() { echo '
'; } /** * Remove coupon. */ public function remove_coupon() { check_ajax_referer( 'wcf-remove-coupon', 'security' ); $coupon = isset( $_POST['coupon_code'] ) ? wc_clean( wp_unslash( $_POST['coupon_code'] ) ) : false; //phpcs:ignore if ( empty( $coupon ) ) { echo "
" . esc_html__( 'Sorry there was a problem removing this coupon.', 'cartflows' ); } else { WC()->cart->remove_coupon( $coupon ); echo "
" . esc_html__( 'Coupon has been removed.', 'cartflows' ) . '
'; } wc_print_notices(); wp_die(); } /** * Remove cart item. */ public function wcf_woo_remove_cart_product() { check_ajax_referer( 'wcf-remove-cart-product', 'security' ); $product_key = isset( $_POST['p_key'] ) ? wc_clean( wp_unslash( $_POST['p_key'] ) ) : false; //phpcs:ignore $product_id = isset( $_POST['p_id'] ) ? wc_clean( wp_unslash( $_POST['p_id'] ) ) : ''; //phpcs:ignore $product_title = get_the_title( $product_id ); $needs_shipping = false; if ( empty( $product_key ) ) { $msg = "
" . __( 'Sorry there was a problem removing ', 'cartflows' ) . $product_title; } else { WC()->cart->remove_cart_item( $product_key ); $msg = "
" . $product_title . __( ' has been removed.', 'cartflows' ) . '
'; } foreach ( WC()->cart->get_cart() as $cart_item_key => $values ) { if ( $values['data']->needs_shipping() ) { $needs_shipping = true; break; } } $response = array( 'need_shipping' => $needs_shipping, 'msg' => $msg, ); echo wp_json_encode( $response ); wp_die(); } } /** * Kicking this off by calling 'get_instance()' method */ Cartflows_Checkout_Markup::get_instance(); checkout/class-cartflows-checkout.php000066600000001635152100564630014007 0ustar00options->get_checkout_meta_value( $checkout_id, 'wcf-checkout-layout' ); $fields_skins = wcf()->options->get_checkout_meta_value( $checkout_id, 'wcf-fields-skins' ); ?>
' ) { do_action( 'cartflows_checkout_cart_empty', $checkout_id ); echo esc_html__( 'Your cart is currently empty.', 'cartflows' ); } else { echo $checkout_html; } ?>
checkout/templates/wcf-template.php000066600000002550152100564630013460 0ustar00 > <?php wp_title( '-', true, 'right' ); ?><?php bloginfo( 'name' ); ?> >
' ) { echo esc_html__( 'Your cart is currently empty.', 'cartflows' ); } else { echo $checkout_html; } ?>
optin/class-cartflows-optin.php000066600000001577152100564630012664 0ustar00elementor_editor_compatibility(); } /** * Elementor editor compatibility. */ public function elementor_editor_compatibility() { if ( ! empty( $_REQUEST['action'] ) && 'elementor' === $_REQUEST['action'] && is_admin() ) { //phpcs:ignore if ( isset( $_GET['post'] ) && ! empty( $_GET['post'] ) ) { //phpcs:ignore if ( _wcf_check_is_optin_by_id( intval( $_GET['post'] ) ) ) { //phpcs:ignore /* Submit Button */ add_filter( 'woocommerce_order_button_text', array( $this, 'place_order_button_text' ), 10, 1 ); } } } } /** * Change order button text . * * @param string $woo_button_text place order. * @return string */ public function place_order_button_text( $woo_button_text ) { $optin_id = get_the_ID(); $wcf_order_button_text = wcf()->options->get_optin_meta_value( $optin_id, 'wcf-submit-button-text' ); if ( ! empty( $wcf_order_button_text ) ) { $woo_button_text = $wcf_order_button_text; } return $woo_button_text; } /** * Display all WooCommerce notices. * * @since 1.1.5 */ public function display_woo_notices() { if ( null != WC()->session && function_exists( 'woocommerce_output_all_notices' ) ) { woocommerce_output_all_notices(); } } /** * Check for checkout flag * * @param bool $is_checkout is checkout. * * @return bool */ public function woo_checkout_flag( $is_checkout ) { if ( ! is_admin() ) { if ( _is_wcf_optin_type() ) { $is_checkout = true; } } return $is_checkout; } /** * Render checkout shortcode markup. * * @param array $atts attributes. * @return string */ public function optin_shortcode_markup( $atts ) { if ( ! function_exists( 'wc_print_notices' ) ) { $notice_out = '

' . __( '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 '

' . __( 'Please place shortcode on Optin step-type only.', 'cartflows' ) . '

'; } global $post; $optin_id = intval( $post->ID ); } $output = ''; ob_start(); do_action( 'cartflows_optin_form_before', $optin_id ); $optin_layout = 'default'; $template_default = CARTFLOWS_OPTIN_DIR . 'templates/optin-template-simple.php'; include $template_default; $output .= ob_get_clean(); return $output; } /** * Configure Cart Data. * * @since 1.0.0 * * @return void */ public function preconfigured_cart_data() { if ( is_admin() ) { return; } global $post; if ( _is_wcf_optin_type() ) { if ( wp_doing_ajax() ) { return; } else { $optin_id = $post->ID; do_action( 'cartflows_optin_before_configure_cart', $optin_id ); $products = wcf()->options->get_optin_meta_value( $optin_id, 'wcf-optin-product' ); if ( ! is_array( $products ) ) { return; } /* Empty the current cart */ WC()->cart->empty_cart(); if ( is_array( $products ) && count( $products ) < 1 ) { wc_add_notice( __( 'No product is selected. Please select a Simple, Virtual and Free product from the meta settings.', 'cartflows' ), 'error' ); return; } /* Set customer session if not set */ if ( ! is_user_logged_in() && WC()->cart->is_empty() ) { WC()->session->set_customer_session_cookie( true ); } $product_id = reset( $products ); $_product = wc_get_product( $product_id ); if ( ! empty( $_product ) ) { if ( $_product->is_type( 'simple' ) && $_product->is_virtual() ) { if ( $_product->get_price() > 0 ) { wc_add_notice( __( 'Please update the selected product\'s price to zero (0).', 'cartflows' ), 'error' ); } else { $quantity = 1; WC()->cart->add_to_cart( $product_id, $quantity ); } } else { wc_add_notice( __( 'Please select a Simple, Virtual and Free product.', 'cartflows' ), 'error' ); } } else { wc_add_notice( __( 'Please select a Simple, Virtual and Free product.', 'cartflows' ), 'error' ); } do_action( 'cartflows_optin_after_configure_cart', $optin_id ); } } } /** * Load shortcode data. * * @return void */ public function shortcode_load_data() { if ( _is_wcf_optin_type() ) { 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' ); // 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 unnecessary option */ add_filter( 'woocommerce_enable_order_notes_field', '__return_false' ); add_filter( 'woocommerce_cart_needs_shipping_address', '__return_false' ); remove_all_actions( 'woocommerce_before_checkout_form' ); remove_all_actions( 'woocommerce_checkout_billing' ); remove_all_actions( 'woocommerce_checkout_shipping' ); remove_all_actions( 'woocommerce_checkout_before_order_review' ); remove_all_actions( 'woocommerce_checkout_order_review' ); remove_all_actions( 'woocommerce_checkout_after_order_review' ); add_filter( 'woocommerce_cart_needs_payment', '__return_false' ); add_filter( 'woocommerce_available_payment_gateways', array( $this, 'disable_payment_gateways' ) ); /* Paypal Expresss remove */ if ( function_exists( 'wc_gateway_ppec' ) ) { remove_action( 'wp_enqueue_scripts', array( wc_gateway_ppec()->cart, 'enqueue_scripts' ) ); } // Hook in actions once. add_action( 'woocommerce_before_checkout_form', 'woocommerce_output_all_notices', 10 ); add_action( 'woocommerce_checkout_billing', array( WC()->checkout, 'checkout_form_billing' ) ); add_action( 'woocommerce_checkout_shipping', array( WC()->checkout, 'checkout_form_shipping' ) ); add_action( 'woocommerce_checkout_order_review', 'woocommerce_checkout_payment', 20 ); /* Submit Button */ add_filter( 'woocommerce_order_button_text', array( $this, 'place_order_button_text' ), 10, 1 ); add_filter( 'woocommerce_get_terms_and_conditions_checkbox_text', '__return_false' ); global $post; $optin_id = $post->ID; do_action( 'cartflows_optin_before_shortcode', $optin_id ); } } /** * Disable payment gateways. * * @param array $available_gateways gateways. * @return array */ public function disable_payment_gateways( $available_gateways ) { if ( ! is_admin() ) { $available_gateways = array(); } return $available_gateways; } /** * Render checkout ID hidden field. * * @param array $checkout checkout session data. * @return void */ public function checkout_shortcode_post_id( $checkout ) { if ( ! _is_wcf_optin_type() ) { return; } global $post; $optin_id = $post->ID; $flow_id = get_post_meta( $optin_id, 'wcf-flow-id', true ); echo ''; echo ''; } /** * Load shortcode scripts. * * @return void */ public function shortcode_scripts() { wp_enqueue_style( 'wcf-optin-template', wcf()->utils->get_css_url( 'optin-template' ), '', CARTFLOWS_VER ); wp_enqueue_script( 'wcf-optin-template', wcf()->utils->get_js_url( 'optin-template' ), array( 'jquery' ), CARTFLOWS_VER, true ); do_action( 'cartflows_optin_scripts' ); $style = $this->generate_style(); wp_add_inline_style( 'wcf-optin-template', $style ); } /** * Load compatibility scripts. * * @return void */ public function compatibility_scripts() { global $post; $optin_id = $post->ID; // 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( $optin_id ) ) { wp_enqueue_style( 'wcf-optin-template-divi', wcf()->utils->get_css_url( 'optin-template-divi' ), '', CARTFLOWS_VER ); } } /** * Generate styles. * * @return string */ public function generate_style() { global $post; $optin_id = $post->ID; /* Load all fonts */ CartFlows_Font_Families::render_fonts( $optin_id ); $r = ''; $g = ''; $b = ''; $output = ''; /* Global */ $primary_color = wcf()->options->get_optin_meta_value( $optin_id, 'wcf-primary-color' ); $base_font_family = wcf()->options->get_optin_meta_value( $optin_id, 'wcf-base-font-family' ); /* Input Fields */ $input_font_family = wcf()->options->get_optin_meta_value( $optin_id, 'wcf-input-font-family' ); $input_font_weight = wcf()->options->get_optin_meta_value( $optin_id, 'wcf-input-font-weight' ); $field_input_size = wcf()->options->get_optin_meta_value( $optin_id, 'wcf-input-field-size' ); $field_tb_padding = wcf()->options->get_optin_meta_value( $optin_id, 'wcf-field-tb-padding' ); $field_lr_padding = wcf()->options->get_optin_meta_value( $optin_id, 'wcf-field-lr-padding' ); $field_color = wcf()->options->get_optin_meta_value( $optin_id, 'wcf-field-color' ); $field_bg_color = wcf()->options->get_optin_meta_value( $optin_id, 'wcf-field-bg-color' ); $field_border_color = wcf()->options->get_optin_meta_value( $optin_id, 'wcf-field-border-color' ); $field_label_color = wcf()->options->get_optin_meta_value( $optin_id, 'wcf-field-label-color' ); if ( 'custom' == $field_input_size ) { $field_input_size = '38px'; } /* Submit Button */ $submit_button_width = '100%'; $optin_button_position = ''; $button_font_size = wcf()->options->get_optin_meta_value( $optin_id, 'wcf-submit-font-size' ); $button_font_family = wcf()->options->get_optin_meta_value( $optin_id, 'wcf-button-font-family' ); $button_font_weight = wcf()->options->get_optin_meta_value( $optin_id, 'wcf-button-font-weight' ); $submit_button_height = wcf()->options->get_optin_meta_value( $optin_id, 'wcf-submit-button-size' ); $submit_tb_padding = wcf()->options->get_optin_meta_value( $optin_id, 'wcf-submit-tb-padding' ); $submit_lr_padding = wcf()->options->get_optin_meta_value( $optin_id, 'wcf-submit-lr-padding' ); $submit_button_position = wcf()->options->get_optin_meta_value( $optin_id, 'wcf-submit-button-position' ); $submit_color = wcf()->options->get_optin_meta_value( $optin_id, 'wcf-submit-color' ); $submit_hover_color = wcf()->options->get_optin_meta_value( $optin_id, 'wcf-submit-hover-color' ); $submit_bg_color = wcf()->options->get_optin_meta_value( $optin_id, 'wcf-submit-bg-color', $primary_color ); $submit_bg_hover_color = wcf()->options->get_optin_meta_value( $optin_id, 'wcf-submit-bg-hover-color', $primary_color ); $submit_border_color = wcf()->options->get_optin_meta_value( $optin_id, 'wcf-submit-border-color', $primary_color ); $submit_border_hover_color = wcf()->options->get_optin_meta_value( $optin_id, 'wcf-submit-border-hover-color', $primary_color ); if ( 'custom' == $submit_button_height ) { $submit_button_height = '38px'; $submit_button_width = 'auto'; switch ( $submit_button_position ) { case 'left': $optin_button_position = '0 auto 0 0'; break; case 'center': $optin_button_position = '0 auto'; break; case 'right': $optin_button_position = '0 0 0 auto'; break; default: $optin_button_position = '0 auto'; break; } } if ( Cartflows_Compatibility::get_instance()->is_divi_enabled() || Cartflows_Compatibility::get_instance()->is_divi_builder_enabled( $optin_id ) ) { include CARTFLOWS_OPTIN_DIR . 'includes/optin-dynamic-divi-css.php'; } else { include CARTFLOWS_OPTIN_DIR . 'includes/optin-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_optin_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_optin_fields( $order_id, $posted ) { if ( isset( $_POST['_wcf_optin_id'] ) ) { //phpcs:ignore $optin_id = wc_clean( wp_unslash( $_POST['_wcf_optin_id'] ) ); //phpcs:ignore update_post_meta( $order_id, '_wcf_optin_id', $optin_id ); if ( isset( $_POST['_wcf_flow_id'] ) ) { //phpcs:ignore $flow_id = wc_clean( wp_unslash( $_POST['_wcf_flow_id'] ) ); //phpcs:ignore update_post_meta( $order_id, '_wcf_flow_id', $flow_id ); } } } /** * Redirect users to our checkout if hidden param * * @param string $redirect redirect url. * @param object $user user. * @return string */ public function after_login_redirect( $redirect, $user ) { if ( isset( $_POST['_wcf_optin_id'] ) ) { //phpcs:ignore $optin_id = intval( $_POST['_wcf_optin_id'] ); //phpcs:ignore $redirect = get_permalink( $optin_id ); } return $redirect; } /** * Add custom class to the fields to change the UI to three column. * * @param array $fields fields. */ public function set_optin_default_fields( $fields ) { if ( _is_wcf_optin_type() ) { global $post; $optin_id = $post->ID; } else { if ( _is_wcf_doing_optin_ajax() && wcf()->utils->get_optin_id_from_post_data() ) { $optin_id = wcf()->utils->get_optin_id_from_post_data(); } else { return $fields; } } $first_name = $fields['first_name']; $last_name = $fields['last_name']; /* Make fields required */ $first_name['required'] = true; $last_name['required'] = true; $fields = array( 'first_name' => $first_name, 'last_name' => $last_name, ); return apply_filters( 'cartflows_optin_default_fields', $fields, $optin_id ); } /** * Add custom class to the fields to change the UI to three column. * * @param array $fields fields. */ public function set_optin_fields( $fields ) { if ( _is_wcf_optin_type() ) { global $post; $optin_id = $post->ID; } else { if ( _is_wcf_doing_optin_ajax() && wcf()->utils->get_optin_id_from_post_data() ) { $optin_id = wcf()->utils->get_optin_id_from_post_data(); } else { return $fields; } } $billing_first_name = $fields['billing']['billing_first_name']; $billing_last_name = $fields['billing']['billing_last_name']; $billing_email = $fields['billing']['billing_email']; $fields['billing'] = array( 'billing_first_name' => $billing_first_name, 'billing_last_name' => $billing_last_name, 'billing_email' => $billing_email, ); return apply_filters( 'cartflows_optin_fields', $fields, $optin_id ); } /** * Billing field customization. * * @param array $fields fields data. * @param string $country country name. * @return array */ public function billing_optin_fields( $fields, $country ) { if ( _is_wcf_optin_type() ) { global $post; $optin_id = $post->ID; } else { if ( _is_wcf_doing_optin_ajax() && wcf()->utils->get_optin_id_from_post_data() ) { $optin_id = wcf()->utils->get_optin_id_from_post_data(); } else { return $fields; } } if ( is_wc_endpoint_url( 'edit-address' ) ) { return $fields; } $billing_first_name = $fields['billing_first_name']; $billing_last_name = $fields['billing_last_name']; $billing_email = $fields['billing_email']; /* Make fields required */ $billing_first_name['required'] = true; $billing_last_name['required'] = true; $fields = array( 'billing_first_name' => $billing_first_name, 'billing_last_name' => $billing_last_name, 'billing_email' => $billing_email, ); return apply_filters( 'cartflows_billing_optin_fields', $fields, $country, $optin_id ); } /** * Replace billing label. * * @param string $notice Notice. * @param string $field_label Field name. * @return string */ public function change_field_label_in_required_notice( $notice, $field_label ) { if ( _is_wcf_doing_optin_ajax() ) { $notice = str_replace( 'Billing ', '', $notice ); } return $notice; } } /** * Kicking this off by calling 'get_instance()' method */ Cartflows_Optin_Markup::get_instance(); optin/classes/class-cartflows-optin-meta.php000066600000045044152100564630015242 0ustar00utils->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-optin-step-meta', 'nonce-optin-step-meta' ); $stored = get_post_meta( $post->ID ); $optin_meta = self::get_meta_option( $post->ID ); // Set stored and override defaults. foreach ( $stored as $key => $value ) { if ( array_key_exists( $key, $optin_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 ); $optin_meta = array(); foreach ( $meta as $key => $value ) { $optin_meta[ $key ] = $meta[ $key ]['default']; } do_action( 'wcf_optin_settings_markup_before' ); $this->tabs_markup( $optin_meta, $post->ID ); do_action( 'wcf_optin_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-optin-shortcodes'; } $tab_array = array( array( 'title' => __( 'Shortcodes', 'cartflows' ), 'id' => 'wcf-optin-shortcodes', 'class' => 'wcf-optin-shortcodes' === $active_tab ? 'wcf-tab wp-ui-text-highlight active' : 'wcf-tab', 'icon' => 'dashicons-editor-code', ), array( 'title' => __( 'Select Product', 'cartflows' ), 'id' => 'wcf-optin-general', 'class' => 'wcf-optin-general' === $active_tab ? 'wcf-tab wp-ui-text-highlight active' : 'wcf-tab', 'icon' => 'dashicons-info', ), array( 'title' => __( 'Design', 'cartflows' ), 'id' => 'wcf-optin-style', 'class' => 'wcf-optin-style' === $active_tab ? 'wcf-tab wp-ui-text-highlight active' : 'wcf-tab', 'icon' => 'dashicons-admin-customizer', ), array( 'title' => __( 'Form Fields', 'cartflows' ), 'id' => 'wcf-optin-custom-fields', 'class' => 'wcf-optin-custom-fields' === $active_tab ? 'wcf-tab wp-ui-text-highlight active' : 'wcf-tab', 'icon' => 'dashicons-welcome-widgets-menus', ), array( 'title' => __( 'Settings', 'cartflows' ), 'id' => 'wcf-optin-custom-settings', 'class' => 'wcf-optin-custom-settings' === $active_tab ? 'wcf-tab wp-ui-text-highlight active' : 'wcf-tab', 'icon' => 'dashicons-admin-generic', ), array( 'title' => __( 'Custom Script', 'cartflows' ), 'id' => 'wcf-optin-custom-script-header', 'class' => 'wcf-optin-custom-script-header' === $active_tab ? 'wcf-tab wp-ui-text-highlight active' : 'wcf-tab', 'icon' => 'dashicons-format-aside', ), ); $tabs = $tab_array; ?>
$tab ) { ?>
tab_shortcodes( $options, $post_id ); ?> tab_general( $options, $post_id ); ?> tab_style( $options, $post_id ); ?> tab_custom_fields( $options, $post_id ); ?> tab_custom_settings( $options, $post_id ); ?> tab_custom_script( $options, $post_id ); ?> right_column_footer( $options, $post_id ); ?>
meta->get_shortcode_field( array( 'label' => 'Optin Page', 'name' => 'wcf-optin-shortcode', 'content' => '[cartflows_optin]', 'help' => esc_html__( 'Add this shortcode to your optin page', 'cartflows' ), ) ); ?>
meta->get_product_selection_field( array( 'name' => 'wcf-optin-product', 'value' => $options['wcf-optin-product'], 'label' => __( 'Select Free Product', 'cartflows' ), 'help' => __( 'Select Free and Virtual product only.', 'cartflows' ), 'multiple' => false, 'allow_clear' => true, ) ); ?>
meta->get_description_field( array( 'name' => 'wcf-upgrade-to-pro', /* translators: %s: link */ 'content' => '' . sprintf( esc_html__( 'Upgrade to %1$sCartFlows Pro%2$s for Custom Fields feature.', 'cartflows' ), '', '' ) . '', ) ); } ?>
meta->get_checkbox_field( array( 'label' => __( 'Pass Fields as URL Parameters', 'cartflows' ), 'name' => 'wcf-optin-pass-fields', 'value' => $options['wcf-optin-pass-fields'], 'after' => __( 'Enable', 'cartflows' ), 'help' => __( 'You can pass specific fields from the form to next step as URL query parameters.', 'cartflows' ), 'toggle' => array( 'fields' => array( 'yes' => array( 'wcf-optin-pass-specific-fields' ), ), ), ) ); echo wcf()->meta->get_text_field( array( 'label' => __( 'Enter form field', 'cartflows' ), 'name' => 'wcf-optin-pass-specific-fields', 'value' => $options['wcf-optin-pass-specific-fields'], 'help' => __( 'Enter comma seprated field name. E.g. first_name, last_name', 'cartflows' ), 'attr' => array( 'placeholder' => __( 'Fields to pass, separated by commas', 'cartflows' ), ), ) ); echo wcf()->meta->get_description_field( array( 'name' => 'wcf-optin-pass-fields-doc', 'content' => __( 'Enter comma seprated field name. E.g. first_name, last_name', 'cartflows' ), /* translators: %s: link */ 'content' => sprintf( esc_html__( 'You can pass field value as a URL parameter to the next step. %1$sClick here%2$s for more information.', 'cartflows' ), '', '' ), ) ); ?>
meta->get_color_picker_field( array( 'label' => __( 'Primary Color', 'cartflows' ), 'name' => 'wcf-primary-color', 'value' => $options['wcf-primary-color'], ) ); echo wcf()->meta->get_font_family_field( array( 'for' => 'wcf-base', 'label' => esc_html__( 'Font Family', 'cartflows' ), 'name' => 'wcf-base-font-family', 'value' => $options['wcf-base-font-family'], ) ); ?>
meta->get_section( array( 'label' => __( 'Input Fields', 'cartflows' ), ) ); $fields_skin_pro_option = array(); if ( ! _is_cartflows_pro() ) { $fields_skin_pro_option = array( 'floating-labels' => __( 'Floating Labels (Available in CartFlows Pro)', 'cartflows' ), ); } echo wcf()->meta->get_select_field( array( 'label' => __( 'Style', 'cartflows' ), 'name' => 'wcf-input-fields-skins', 'value' => $options['wcf-input-fields-skins'], 'options' => array( 'default' => esc_html__( 'Default', 'cartflows' ), 'floating-labels' => esc_html__( 'Floating Labels', 'cartflows' ), ), 'pro-options' => $fields_skin_pro_option, ) ); echo wcf()->meta->get_font_family_field( array( 'for' => 'wcf-input', 'label' => esc_html__( 'Font Family', 'cartflows' ), 'name' => 'wcf-input-font-family', 'value' => $options['wcf-input-font-family'], ) ); echo wcf()->meta->get_font_weight_field( array( 'for' => 'wcf-input', 'label' => esc_html__( 'Font Weight', 'cartflows' ), 'name' => 'wcf-input-font-weight', 'value' => $options['wcf-input-font-weight'], ) ); echo wcf()->meta->get_select_field( array( 'label' => __( 'Size', 'cartflows' ), 'name' => 'wcf-input-field-size', 'value' => $options['wcf-input-field-size'], 'options' => array( '33px' => esc_html__( 'Extra Small', 'cartflows' ), '38px' => esc_html__( 'Small', 'cartflows' ), '44px' => esc_html__( 'Medium', 'cartflows' ), '58px' => esc_html__( 'Large', 'cartflows' ), '68px' => esc_html__( 'Extra Large', 'cartflows' ), 'custom' => esc_html__( 'Custom', 'cartflows' ), ), ) ); echo wcf()->meta->get_number_field( array( 'label' => __( 'Top Bottom Spacing', 'cartflows' ), 'name' => 'wcf-field-tb-padding', 'value' => $options['wcf-field-tb-padding'], ) ); echo wcf()->meta->get_number_field( array( 'label' => __( 'Left Right Spacing', 'cartflows' ), 'name' => 'wcf-field-lr-padding', 'value' => $options['wcf-field-lr-padding'], ) ); echo wcf()->meta->get_color_picker_field( array( 'label' => __( 'Label Color', 'cartflows' ), 'name' => 'wcf-field-label-color', 'value' => $options['wcf-field-label-color'], ) ); echo wcf()->meta->get_color_picker_field( array( 'label' => __( 'Text / Placeholder Color', 'cartflows' ), 'name' => 'wcf-field-color', 'value' => $options['wcf-field-color'], ) ); echo wcf()->meta->get_color_picker_field( array( 'label' => __( 'Background Color', 'cartflows' ), 'name' => 'wcf-field-bg-color', 'value' => $options['wcf-field-bg-color'], ) ); echo wcf()->meta->get_color_picker_field( array( 'label' => __( 'Border Color', 'cartflows' ), 'name' => 'wcf-field-border-color', 'value' => $options['wcf-field-border-color'], ) ); ?>
meta->get_section( array( 'label' => __( 'Submit Button', 'cartflows' ), ) ); echo wcf()->meta->get_text_field( array( 'label' => __( 'Button Text', 'cartflows' ), 'name' => 'wcf-submit-button-text', 'value' => $options['wcf-submit-button-text'], 'attr' => array( 'placeholder' => __( 'Submit', 'cartflows' ), ), ) ); echo wcf()->meta->get_number_field( array( 'label' => __( 'Font Size', 'cartflows' ), 'name' => 'wcf-submit-font-size', 'value' => $options['wcf-submit-font-size'], ) ); echo wcf()->meta->get_font_family_field( array( 'for' => 'wcf-button', 'label' => esc_html__( 'Font Family', 'cartflows' ), 'name' => 'wcf-button-font-family', 'value' => $options['wcf-button-font-family'], ) ); echo wcf()->meta->get_font_weight_field( array( 'for' => 'wcf-button', 'label' => esc_html__( 'Font Weight', 'cartflows' ), 'name' => 'wcf-button-font-weight', 'value' => $options['wcf-button-font-weight'], ) ); echo wcf()->meta->get_select_field( array( 'label' => __( 'Size', 'cartflows' ), 'name' => 'wcf-submit-button-size', 'value' => $options['wcf-submit-button-size'], 'options' => array( '33px' => esc_html__( 'Extra Small', 'cartflows' ), '38px' => esc_html__( 'Small', 'cartflows' ), '44px' => esc_html__( 'Medium', 'cartflows' ), '58px' => esc_html__( 'Large', 'cartflows' ), '68px' => esc_html__( 'Extra Large', 'cartflows' ), 'custom' => esc_html__( 'Custom', 'cartflows' ), ), ) ); echo wcf()->meta->get_number_field( array( 'label' => __( 'Top Bottom Spacing', 'cartflows' ), 'name' => 'wcf-submit-tb-padding', 'value' => $options['wcf-submit-tb-padding'], ) ); echo wcf()->meta->get_number_field( array( 'label' => __( 'Left Right Spacing', 'cartflows' ), 'name' => 'wcf-submit-lr-padding', 'value' => $options['wcf-submit-lr-padding'], ) ); echo wcf()->meta->get_select_field( array( 'label' => __( 'Position', 'cartflows' ), 'name' => 'wcf-submit-button-position', 'value' => $options['wcf-submit-button-position'], 'options' => array( 'left' => esc_html__( 'Left', 'cartflows' ), 'center' => esc_html__( 'Center', 'cartflows' ), 'right' => esc_html__( 'Right', 'cartflows' ), ), ) ); echo wcf()->meta->get_color_picker_field( array( 'label' => __( 'Text Color', 'cartflows' ), 'name' => 'wcf-submit-color', 'value' => $options['wcf-submit-color'], ) ); echo wcf()->meta->get_color_picker_field( array( 'label' => __( 'Text Hover Color', 'cartflows' ), 'name' => 'wcf-submit-hover-color', 'value' => $options['wcf-submit-hover-color'], ) ); echo wcf()->meta->get_color_picker_field( array( 'label' => __( 'Background Color', 'cartflows' ), 'name' => 'wcf-submit-bg-color', 'value' => $options['wcf-submit-bg-color'], ) ); echo wcf()->meta->get_color_picker_field( array( 'label' => __( 'Background Hover Color', 'cartflows' ), 'name' => 'wcf-submit-bg-hover-color', 'value' => $options['wcf-submit-bg-hover-color'], ) ); echo wcf()->meta->get_color_picker_field( array( 'label' => __( 'Border Color', 'cartflows' ), 'name' => 'wcf-submit-border-color', 'value' => $options['wcf-submit-border-color'], ) ); echo wcf()->meta->get_color_picker_field( array( 'label' => __( 'Border Hover Color', 'cartflows' ), 'name' => 'wcf-submit-border-hover-color', 'value' => $options['wcf-submit-border-hover-color'], ) ); ?>
meta->get_hidden_field( array( 'name' => 'wcf-field-google-font-url', 'value' => $options['wcf-field-google-font-url'], ) ); ?>
options->get_optin_fields( $post_id ); } return self::$meta_option; } /** * Metabox Save * * @param number $post_id Post ID. * @return void */ public function save_meta_box( $post_id ) { // Checks save status. $is_autosave = wp_is_post_autosave( $post_id ); $is_revision = wp_is_post_revision( $post_id ); $is_valid_nonce = ( isset( $_POST['nonce-optin-step-meta'] ) && wp_verify_nonce( sanitize_text_field( wp_unslash( $_POST['nonce-optin-step-meta'] ) ), 'save-nonce-optin-step-meta' ) ) ? true : false; // Exits script depending on save status. if ( $is_autosave || $is_revision || ! $is_valid_nonce ) { return; } wcf()->options->save_optin_fields( $post_id ); } } /** * Kicking this off by calling 'get_instance()' method */ Cartflows_Optin_Meta::get_instance(); optin/templates/optin-template-simple.php000066600000001431152100564630014642 0ustar00options->get_optin_meta_value( $optin_id, 'wcf-input-fields-skins' ); ?>
' ) { echo esc_html__( 'Your cart is currently empty.', 'cartflows' ); } else { echo $checkout_html; } ?> landing/classes/class-cartflows-landing-meta.php000066600000013251152100564630016003 0ustar00utils->get_step_post_type(), // Post_type. 'normal', // Context. 'high' // Priority. ); } } /** * Landing Metabox Markup * * @param object $post Post object. * @return void */ public function landing_meta_box( $post ) { wp_nonce_field( 'save-nonce-landing-step-meta', 'nonce-landing-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 ); /** * Get options */ $landing_data = array(); foreach ( $meta as $key => $value ) { $landing_data[ $key ] = $meta[ $key ]['default']; } do_action( 'wcf_landing_settings_markup_before', $meta ); $this->page_header_tab( $landing_data, $post->ID ); do_action( 'wcf_landing_settings_markup_after', $meta ); } /** * Page Header Tabs * * @param array $options Post meta. * @param int $post_id Post ID. */ public function page_header_tab( $options, $post_id ) { $active_tab = get_post_meta( $post_id, 'wcf_active_tab', true ); if ( empty( $active_tab ) ) { $active_tab = 'wcf-landing-shortcodes'; } $tabs = array( array( 'title' => __( 'Shortcodes', 'cartflows' ), 'id' => 'wcf-landing-shortcodes', 'class' => 'wcf-landing-shortcodes' === $active_tab ? 'wcf-tab wp-ui-text-highlight active' : 'wcf-tab', 'icon' => 'dashicons-info', ), array( 'title' => __( 'Custom Script', 'cartflows' ), 'id' => 'wcf-landing-custom-script-header', 'class' => 'wcf-landing-custom-script-header' === $active_tab ? 'wcf-tab wp-ui-text-highlight active' : 'wcf-tab', 'icon' => 'dashicons-format-aside', ), ); ?>
$tab ) { ?>
utils->get_linking_url( array( 'class' => 'wcf-next-step' ) ); echo wcf()->meta->get_shortcode_field( array( 'label' => __( 'Next Step Link', 'cartflows' ), 'name' => 'wcf-next-step-link', 'content' => $next_step_link, ) ); ?>
tab_custom_script( $options, $post_id ); ?> right_column_footer( $options, $post_id ); ?>
options->get_landing_fields( $post_id ); } return self::$meta_option; } /** * Metabox Save * * @param number $post_id Post ID. * @return void */ public function save_meta_box( $post_id ) { // Checks save status. $is_autosave = wp_is_post_autosave( $post_id ); $is_revision = wp_is_post_revision( $post_id ); $is_valid_nonce = ( isset( $_POST['nonce-landing-step-meta'] ) && wp_verify_nonce( sanitize_text_field( wp_unslash( $_POST['nonce-landing-step-meta'] ) ), 'save-nonce-landing-step-meta' ) ) ? true : false; // Exits script depending on save status. if ( $is_autosave || $is_revision || ! $is_valid_nonce ) { return; } wcf()->options->save_landing_fields( $post_id ); } } /** * Kicking this off by calling 'get_instance()' method */ Cartflows_Landing_Meta::get_instance(); landing/classes/class-cartflows-landing-markup.php000066600000005725152100564630016363 0ustar00 CARTFLOWS_STEP_POST_TYPE, 'numberposts' => 100, 'meta_query' => array( //phpcs:ignore 'relation' => 'OR', array( 'key' => 'wcf-step-type', 'value' => 'landing', ), array( 'key' => 'wcf-step-type', 'value' => 'checkout', ), array( 'key' => 'wcf-step-type', 'value' => 'optin', ), ), ); $landing_pages = get_posts( $args ); if ( is_array( $landing_pages ) && ! empty( $landing_pages ) ) { $cartflows_custom_option = ''; $front_page_id = get_option( 'page_on_front' ); foreach ( $landing_pages as $key => $landing_page ) { $selected = selected( $front_page_id, $landing_page->ID, false ); $cartflows_custom_option .= ""; } $cartflows_custom_option .= ''; $output = str_replace( '', $cartflows_custom_option, $output ); } } return $output; } /** * Set post query. * * @param string $query post query. */ public function wcf_pre_get_posts( $query ) { if ( $query->is_main_query() && ! ( defined( 'DOING_AJAX' ) && DOING_AJAX ) ) { $post_type = $query->get( 'post_type' ); $page_id = $query->get( 'page_id' ); if ( empty( $post_type ) && ! empty( $page_id ) ) { $query->set( 'post_type', get_post_type( $page_id ) ); } } } /** * Redirect to homepage if landing page set as home page. */ public function template_redirect() { $compatibiliy = Cartflows_Compatibility::get_instance(); // Do not redirect for page builder preview. if ( $compatibiliy->is_page_builder_preview() ) { return; } global $post; if ( is_singular() && ! is_front_page() && get_option( 'page_on_front' ) == $post->ID ) { wp_safe_redirect( site_url(), 301 ); } } } /** * Kicking this off by calling 'get_instance()' method */ Cartflows_Landing_Markup::get_instance(); landing/class-cartflows-landing.php000066600000001615152100564630013423 0ustar00 __( 'Landing', 'cartflows' ), 'checkout' => __( 'Checkout (Woo)', 'cartflows' ), 'thankyou' => __( 'Thank You (Woo)', 'cartflows' ), 'upsell' => __( 'Upsell (Woo)', 'cartflows' ), 'downsell' => __( 'Downsell (Woo)', 'cartflows' ), 'optin' => __( 'Optin (Woo)', 'cartflows' ), ); ?>
$data ) { ?>

$step ) { wp_delete_post( $step['id'], true ); } } $term_data = term_exists( 'flow-' . $pid, CARTFLOWS_TAXONOMY_STEP_FLOW ); if ( is_array( $term_data ) ) { wp_delete_term( $term_data['term_id'], CARTFLOWS_TAXONOMY_STEP_FLOW ); } } } /** * Trash steps data after trashing flow. * * @since 1.0.0 * @param int $pid post id. * * @return void */ public function step_post_trash_sync( $pid ) { global $post_type; if ( CARTFLOWS_FLOW_POST_TYPE === $post_type ) { $steps = get_post_meta( $pid, 'wcf-steps', true ); if ( $steps && is_array( $steps ) ) { foreach ( $steps as $i => $step ) { wp_trash_post( $step['id'] ); } } } } /** * Untrash steps data after restoring flow. * * @since 1.0.0 * @param int $pid post id. * * @return void */ public function step_post_untrash_sync( $pid ) { global $post_type; if ( CARTFLOWS_FLOW_POST_TYPE === $post_type ) { $steps = get_post_meta( $pid, 'wcf-steps', true ); if ( $steps && is_array( $steps ) ) { foreach ( $steps as $i => $step ) { wp_untrash_post( $step['id'] ); } } } } /** * Create step for given flow. * * @param int $flow_id flow ID. * @param int $step_type step type. * @param int $step_title step title. * @since 1.0.0 * * @return int */ public function create_step( $flow_id, $step_type, $step_title ) { $new_step_id = wp_insert_post( array( 'post_type' => CARTFLOWS_STEP_POST_TYPE, 'post_title' => $step_title, 'post_status' => 'publish', ) ); if ( $new_step_id ) { $flow_steps = get_post_meta( $flow_id, 'wcf-steps', true ); if ( ! is_array( $flow_steps ) ) { $flow_steps = array(); } $flow_steps[] = array( 'id' => $new_step_id, 'title' => $step_title, 'type' => $step_type, ); // insert post meta. update_post_meta( $new_step_id, 'wcf-flow-id', $flow_id ); update_post_meta( $new_step_id, 'wcf-step-type', $step_type ); wp_set_object_terms( $new_step_id, $step_type, CARTFLOWS_TAXONOMY_STEP_TYPE ); wp_set_object_terms( $new_step_id, 'flow-' . $flow_id, CARTFLOWS_TAXONOMY_STEP_FLOW ); } update_post_meta( $flow_id, 'wcf-steps', $flow_steps ); return $new_step_id; } /** * Delete step for flow * * @since 1.0.0 * * @return void */ public function cartflows_delete_flow_step() { if ( ! current_user_can( 'manage_options' ) ) { return; } check_ajax_referer( 'wcf-delete-flow-step', 'security' ); if ( isset( $_POST['post_id'] ) && isset( $_POST['step_id'] ) ) { $flow_id = intval( $_POST['post_id'] ); $step_id = intval( $_POST['step_id'] ); } $result = array( 'status' => false, /* translators: %s flow id */ 'text' => sprintf( __( 'Step not deleted for flow - %s', 'cartflows' ), $flow_id ), ); if ( ! $flow_id || ! $step_id ) { wp_send_json( $result ); } wp_delete_post( $step_id, true ); $flow_steps = get_post_meta( $flow_id, 'wcf-steps', true ); if ( ! is_array( $flow_steps ) ) { wp_send_json( $result ); } foreach ( $flow_steps as $index => $data ) { if ( intval( $data['id'] ) === $step_id ) { unset( $flow_steps[ $index ] ); break; } } /* Set index order properly */ $flow_steps = array_merge( $flow_steps ); update_post_meta( $flow_id, 'wcf-steps', $flow_steps ); $result = array( 'status' => true, /* translators: %s flow id */ 'text' => sprintf( __( 'Step deleted for flow - %s', 'cartflows' ), $flow_id ), ); wp_send_json( $result ); } /** * Reorder step flow * * @since 1.0.0 * * @return void */ public function cartflows_reorder_flow_steps() { if ( ! current_user_can( 'manage_options' ) ) { return; } check_ajax_referer( 'wcf-reorder-flow-steps', 'security' ); if ( isset( $_POST['post_id'] ) && isset( $_POST['step_ids'] ) ) { $flow_id = intval( $_POST['post_id'] ); $step_ids = array_map( 'intval', $_POST['step_ids'] ); } $result = array( 'status' => false, /* translators: %s flow id */ 'text' => sprintf( __( 'Steps not sorted for flow - %s', 'cartflows' ), $flow_id ), ); if ( ! $flow_id || ! is_array( $step_ids ) ) { wp_send_json( $result ); } $new_flow_steps = array(); foreach ( $step_ids as $index => $step_id ) { $new_flow_steps[] = array( 'id' => intval( $step_id ), 'title' => get_the_title( $step_id ), 'type' => get_post_meta( $step_id, 'wcf-step-type', true ), ); } update_post_meta( $flow_id, 'wcf-steps', $new_flow_steps ); $result = array( 'status' => true, /* translators: %s flow id */ 'text' => sprintf( __( 'Steps sorted for flow - %s', 'cartflows' ), $flow_id ), ); wp_send_json( $result ); } /** * Load admin scripts * * @since 1.0.0 * * @return void */ public function admin_scripts() { global $pagenow; global $post; $screen = get_current_screen(); if ( ( 'post-new.php' == $pagenow || 'post.php' == $pagenow ) && CARTFLOWS_FLOW_POST_TYPE == $screen->post_type ) { wp_enqueue_script( 'wcf-flow-meta', CARTFLOWS_URL . 'admin/assets/js/flow-admin-edit.js', array( 'jquery', 'jquery-ui-sortable' ), CARTFLOWS_VER, true ); wp_enqueue_style( 'wcf-flow-meta', CARTFLOWS_URL . 'admin/assets/css/flow-admin-edit.css', '', CARTFLOWS_VER ); wp_style_add_data( 'wcf-flow-meta', 'rtl', 'replace' ); $localize = array( 'ajax_url' => admin_url( 'admin-ajax.php' ), ); wp_localize_script( 'jquery', 'cartflows', apply_filters( 'wcf_js_localize', $localize ) ); } } /** * Initialize meta box * * @since 1.0.0 * * @return void */ public function init_metabox() { /** * Fires after the title field. * * @param WP_Post $post Post object. */ add_action( 'add_meta_boxes', array( $this, 'settings_meta_box' ) ); add_action( 'edit_form_after_title', array( $this, 'setup_meta_box' ) ); add_action( 'save_post', array( $this, 'save_meta_box' ) ); } /** * Is first time import? * * @param integer $post_id post ID. * @return bool */ public function is_flow_imported( $post_id = 0 ) { if ( 0 === $post_id ) { $post_id = get_the_ID(); } $steps = get_post_meta( $post_id, 'wcf-steps', true ); $choice = get_post_meta( $post_id, 'wcf-flow-choise', true ); if ( empty( $steps ) && 'import' === $choice ) { return true; } return false; } /** * Setup meta box. * * @return void */ public function setup_meta_box() { if ( ! Cartflows_Admin::is_flow_edit_admin() ) { return; } /** * Adding Add new step button to the top*/ echo $this->add_add_new_step_button(); $this->markup_meta_box(); $this->add_upgrade_to_pro_metabox(); } /** * Add metabox when cartflows pro is not enabled. */ public function add_upgrade_to_pro_metabox() { if ( ! _is_cartflows_pro() ) { add_meta_box( 'wcf-upgrade-pro', __( 'Analytics', 'cartflows' ), array( $this, 'upgrade_to_pro' ), CARTFLOWS_FLOW_POST_TYPE, 'side', 'high' ); } } /** * Show Upgrade To Pro markup. */ public function upgrade_to_pro() { echo '
'; /* translators: %s: link */ echo '

' . sprintf( esc_html__( 'Upgrade to %1$sCartFlows Pro%2$s for Analytics feature', 'cartflows' ), '', '' ) . '

'; echo '

' . esc_html__( 'Get Pro', 'cartflows' ) . '

'; echo '
'; } /** * Settings meta box. * * @return void */ public function settings_meta_box() { if ( CARTFLOWS_FLOW_POST_TYPE === get_post_type() ) { /* No need of sandbox will delete it later */ add_meta_box( 'wcf-sandbox-settings', // Id. __( 'Flow Settings', 'cartflows' ), // Title. array( $this, 'sandbox_meta_box' ), // Callback. CARTFLOWS_FLOW_POST_TYPE, // Post_type. 'side', // Context. 'high' // Priority. ); do_action( 'cartflows_add_flow_metabox' ); } } /** * Metabox Markup * * @return void */ public function markup_meta_box() { global $post; wp_nonce_field( 'save-nonce-flow-meta', 'nonce-flow-meta' ); // Get defaults. $meta = self::get_current_post_meta( $post->ID ); /** * Get options */ $updated_data = array( 'steps' => $meta['wcf-steps']['default'], ); do_action( 'wcf_flow_settings_markup_before', $meta ); $this->page_header_tab( $updated_data ); do_action( 'wcf_flow_settings_markup_after', $meta ); } /** * Metabox Markup * * @param object $post Post object. * @return void */ public function sandbox_meta_box( $post ) { // Get defaults. $meta = self::get_current_post_meta( $post->ID ); /** * Get options */ foreach ( $meta as $key => $value ) { $updated_data[ $key ] = $meta[ $key ]['default']; } do_action( 'wcf_flow_sandbox_markup_before', $meta ); $this->sandbox_markup( $updated_data ); do_action( 'wcf_flow_sandbox_markup_after', $meta ); } /** * Page Header Tabs * * @param array $options Post meta. * @return void */ public function page_header_tab( $options ) { include_once CARTFLOWS_FLOW_DIR . 'view/meta-flow-steps.php'; } /** * Sandbox Markup * * @param array $options Post meta. * @return void */ public function sandbox_markup( $options ) { ?>
meta->get_checkbox_field( array( 'name' => 'wcf-testing', 'value' => $options['wcf-testing'], 'after' => esc_html__( 'Enable Test Mode', 'cartflows' ), ) ); echo wcf()->meta->get_description_field( array( 'name' => 'wcf-testing-note', 'content' => esc_html__( 'If you are using WooCommerce plugin then test mode will add random products in your flow, so you can preview it easily while testing.', 'cartflows' ), ) ); ?>
options->get_flow_fields( $post_id ); } return self::$meta_option; } /** * Get metabox options * * @param int $post_id post ID. * @return array */ public static function get_current_post_meta( $post_id ) { $stored = get_post_meta( $post_id ); $default_meta = self::get_meta_option( $post_id ); // Set stored and override defaults. foreach ( $stored as $key => $value ) { if ( array_key_exists( $key, $default_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] : ''; } } return self::get_meta_option( $post_id ); } /** * Metabox Save * * @param number $post_id Post ID. * @return void */ public function save_meta_box( $post_id ) { // Checks save status. $is_autosave = wp_is_post_autosave( $post_id ); $is_revision = wp_is_post_revision( $post_id ); $is_valid_nonce = ( isset( $_POST['nonce-flow-meta'] ) && wp_verify_nonce( sanitize_text_field( wp_unslash( $_POST['nonce-flow-meta'] ) ), 'save-nonce-flow-meta' ) ) ? true : false; // Exits script depending on save status. if ( $is_autosave || $is_revision || ! $is_valid_nonce ) { return; } wcf()->options->save_flow_fields( $post_id ); } /** * Localize variables in admin * * @param array $vars variables. */ public function localize_vars( $vars ) { $ajax_actions = array( 'wcf_setup_default_steps', 'wcf_add_flow_step', 'wcf_delete_flow_step', 'wcf_reorder_flow_steps', ); foreach ( $ajax_actions as $action ) { $vars[ $action . '_nonce' ] = wp_create_nonce( str_replace( '_', '-', $action ) ); } return $vars; } /** * Add New Step Button * * @return string */ public function add_add_new_step_button() { $add_new_btn_markup = ''; $add_new_btn_markup .= "
"; $add_new_btn_markup .= "'; $add_new_btn_markup .= '
'; return $add_new_btn_markup; } } /** * Kicking this off by calling 'get_instance()' method */ Cartflows_Flow_Meta::get_instance(); flow/classes/class-cartflows-step-post-meta.php000066600000001062152100564630015655 0ustar00post_type ) && CARTFLOWS_STEP_POST_TYPE === $post->post_type ) { $flow_id = get_post_meta( $post->ID, 'wcf-flow-id', true ); $flow_title = get_the_title( $flow_id ); $post_states['cartflows_step'] = '( ' . __( 'Flow: ', 'cartflows' ) . $flow_id . ' | ' . __( 'Name: ', 'cartflows' ) . $flow_title . ')'; } return $post_states; } /** * Display slugdiv. * * @param array $hidden metaboxes. * @param obj $screen screen. * @return array */ public function display_flow_slug_meta_box( $hidden, $screen ) { $post_type = $screen->id; if ( ! empty( $post_type ) && CARTFLOWS_FLOW_POST_TYPE === $post_type ) { $pos = array_search( 'slugdiv', $hidden, true ); unset( $hidden[ $pos ] ); } return $hidden; } /** * Create custom post type */ public function flow_post_type() { $labels = array( 'name' => esc_html_x( 'Flows', 'flow general name', 'cartflows' ), 'singular_name' => esc_html_x( 'Flow', 'flow singular name', 'cartflows' ), 'search_items' => esc_html__( 'Search Flows', 'cartflows' ), 'all_items' => esc_html__( 'All Flows', 'cartflows' ), 'edit_item' => esc_html__( 'Edit Flow', 'cartflows' ), 'view_item' => esc_html__( 'View Flow', 'cartflows' ), 'add_new' => esc_html__( 'Add New', 'cartflows' ), 'update_item' => esc_html__( 'Update Flow', 'cartflows' ), 'add_new_item' => esc_html__( 'Add New', 'cartflows' ), 'new_item_name' => esc_html__( 'New Flow Name', 'cartflows' ), ); $args = array( 'labels' => $labels, 'show_in_menu' => false, 'public' => false, // it's not public, not own permalink. 'publicly_queryable' => true, // you should be able to query it. 'show_ui' => true, 'query_var' => true, 'can_export' => true, 'show_in_admin_bar' => true, 'exclude_from_search' => true, 'has_archive' => false, // it shouldn't have archive page. 'rewrite' => false, // it shouldn't have rewrite rules. 'supports' => array( 'title', 'thumbnail', 'slug' ), 'capability_type' => 'post', ); if ( ! _is_cartflows_pro() ) { $flow_posts = get_posts( array( 'posts_per_page' => 4, 'post_type' => CARTFLOWS_FLOW_POST_TYPE, 'post_status' => array( 'publish', 'pending', 'draft', 'future', 'private', 'inherit', 'trash' ), ) ); if ( is_array( $flow_posts ) ) { $flow_count = count( $flow_posts ); if ( $flow_count > 3 || 3 === $flow_count ) { $args['capabilities'] = array( 'create_posts' => 'do_not_allow', ); $args['map_meta_cap'] = true; // Add new notice button. add_action( 'admin_print_footer_scripts', array( $this, 'add_new_notice_button' ) ); // Add the notice popup HTML to admin footer. add_action( 'admin_footer', array( $this, 'upgrade_to_pro_notice_popup' ) ); } } } register_post_type( CARTFLOWS_FLOW_POST_TYPE, $args ); } /** * Show custom add new button. */ public function add_new_notice_button() { $screen = get_current_screen(); if ( is_object( $screen ) && CARTFLOWS_FLOW_POST_TYPE === $screen->post_type && 'edit-cartflows_flow' === $screen->id ) { ?> get_first_step_url( $post ); if ( $first_step && isset( $actions['view'] ) ) { $actions['view'] = '' . __( 'View', 'cartflows' ) . ''; } return $actions; } /** * Returns previous post link * * @param string $prev_link previous link. * @param array $post post data. * @return string */ public function preview_post_link( $prev_link, $post ) { if ( $this->is_flow_post_type( $post ) ) { $first_step = $this->get_first_step_url( $post ); if ( $first_step ) { return $first_step; } return ''; } return $prev_link; } /** * Check if post type is flow * * @param array $post post data. * @return bool */ public function is_flow_post_type( $post ) { if ( isset( $post ) && CARTFLOWS_FLOW_POST_TYPE === $post->post_type ) { return true; } return false; } /** * Redirect to first step * * @return void */ public function redirect_to_step() { global $post; $first_step = $this->get_first_step_url( $post ); if ( $first_step ) { wp_safe_redirect( $first_step ); die; } } /** * Return first step URL * * @param array $post post data. * @return bool */ public function get_first_step_url( $post ) { if ( $this->is_flow_post_type( $post ) ) { $flow_id = $post->ID; $title = $post->post_title; $steps = get_post_meta( $flow_id, 'wcf-steps', true ); if ( is_array( $steps ) && ! empty( $steps ) && isset( $steps[0]['id'] ) ) { return get_permalink( $steps[0]['id'] ); } } return false; } /** * Register the admin menu for Custom Layouts * * @since 1.0.0 * Moved the menu under Appearance -> Custom Layouts public function register_admin_menu() { add_submenu_page( CARTFLOWS_SLUG, __( 'Flows', 'wcf' ), __( 'Flows', 'wcf' ), 'edit_pages', 'edit.php?post_type=' . CARTFLOWS_FLOW_POST_TYPE ); } */ public function register_as_submenu() { global $submenu; $submenu[ CARTFLOWS_SLUG ][0] = array( //phpcs:ignore __( 'Flows', 'cartflows' ), 'edit_pages', 'edit.php?post_type=' . CARTFLOWS_FLOW_POST_TYPE, ); } /** * Add Update messages for any custom post type * * @param array $messages Array of default messages. */ public function custom_post_type_post_update_messages( $messages ) { $custom_post_type = get_post_type( get_the_ID() ); if ( CARTFLOWS_FLOW_POST_TYPE == $custom_post_type ) { $obj = get_post_type_object( $custom_post_type ); $singular_name = $obj->labels->singular_name; $messages[ $custom_post_type ] = array( 0 => '', // Unused. Messages start at index 1. /* translators: %s: singular custom post type name */ 1 => sprintf( __( '%s updated.', 'cartflows' ), $singular_name ), /* translators: %s: singular custom post type name */ 2 => sprintf( __( 'Custom %s updated.', 'cartflows' ), $singular_name ), /* translators: %s: singular custom post type name */ 3 => sprintf( __( 'Custom %s deleted.', 'cartflows' ), $singular_name ), /* translators: %s: singular custom post type name */ 4 => sprintf( __( '%s updated.', 'cartflows' ), $singular_name ), /* translators: %1$s: singular custom post type name ,%2$s: date and time of the revision */ 5 => isset( $_GET['revision'] ) ? sprintf( __( '%1$s restored to revision from %2$s', 'cartflows' ), $singular_name, wp_post_revision_title( (int) $_GET['revision'], false ) ) : false, //phpcs:ignore /* translators: %s: singular custom post type name */ 6 => sprintf( __( '%s published.', 'cartflows' ), $singular_name ), /* translators: %s: singular custom post type name */ 7 => sprintf( __( '%s saved.', 'cartflows' ), $singular_name ), /* translators: %s: singular custom post type name */ 8 => sprintf( __( '%s submitted.', 'cartflows' ), $singular_name ), /* translators: %s: singular custom post type name */ 9 => sprintf( __( '%s scheduled for.', 'cartflows' ), $singular_name ), /* translators: %s: singular custom post type name */ 10 => sprintf( __( '%s draft updated.', 'cartflows' ), $singular_name ), ); } return $messages; } } /** * Kicking this off by calling 'get_instance()' method */ Cartflows_Flow_Post_Type::get_instance(); flow/classes/class-cartflows-permalink.php000066600000010270152100564630014756 0ustar00post_type ) && CARTFLOWS_STEP_POST_TYPE == $post->post_type ) { $flow_id = get_post_meta( $post->ID, 'wcf-flow-id', true ); $flow_name = get_post_field( 'post_name', $flow_id ); $cf_permalink = Cartflows_Helper::get_permalink_settings(); if ( isset( $cf_permalink['permalink_structure'] ) && ! empty( $cf_permalink['permalink_structure'] ) ) { $search = array( 'cartflows_flow', '%flowname%', 'cartflows_step' ); $replace = array( $cf_permalink['permalink_flow_base'], $flow_name, $cf_permalink['permalink'] ); $post_link = str_replace( $search, $replace, $post_link ); } else { // If elementor page preview, return post link as it is. if ( isset( $_REQUEST['elementor-preview'] ) ) { //phpcs:ignore return $post_link; } $structure = get_option( 'permalink_structure' ); if ( '/%postname%/' === $structure ) { $post_link = str_replace( '/' . $post->post_type . '/', '/', $post_link ); } } } return $post_link; } /** * Reqrite rules for acrtflows step. */ public function rewrite_step_rule() { $cf_permalink = Cartflows_Helper::get_permalink_settings(); if ( isset( $cf_permalink['permalink_structure'] ) ) { switch ( $cf_permalink['permalink_structure'] ) { case '/cartflows_flow/%flowname%/cartflows_step': add_rewrite_rule( '^' . $cf_permalink['permalink_flow_base'] . '/([^/]*)/' . $cf_permalink['permalink'] . '/([^\/]*)/?', 'index.php?cartflows_step=$matches[2]', 'top' ); break; case '/cartflows_flow/%flowname%': add_rewrite_rule( '^' . $cf_permalink['permalink_flow_base'] . '/([^/]*)/([^/]*)/?', 'index.php?cartflows_step=$matches[2]', 'top' ); break; case '/%flowname%/cartflows_step': add_rewrite_rule( '([^/]*)/' . $cf_permalink['permalink'] . '/([^\/]*)/?', 'index.php?cartflows_step=$matches[2]', 'top' ); break; default: break; } } } /** * Have WordPress match postname to any of our public post types. * All of our public post types can have /post-name/ as the slug, so they need to be unique across all posts. * By default, WordPress only accounts for posts and pages where the slug is /post-name/. * * @param string $query query statement. */ public function add_cpt_post_names_to_main_query( $query ) { // Bail if this is not the main query. if ( ! $query->is_main_query() ) { return; } // Bail if this query doesn't match our very specific rewrite rule. if ( ! isset( $query->query['thrive-variations'] ) && ! isset( $query->query['page'] ) || 2 !== count( $query->query ) ) { return; } // Bail if we're not querying based on the post name. if ( empty( $query->query['name'] ) ) { return; } // Add cartflows step post type to existing post type array. if ( isset( $query->query_vars['post_type'] ) && is_array( $query->query_vars['post_type'] ) ) { $post_types = $query->query_vars['post_type']; $post_types[] = CARTFLOWS_STEP_POST_TYPE; $query->set( 'post_type', $post_types ); } else { // Add CPT to the list of post types WP will include when it queries based on the post name. $query->set( 'post_type', array( 'post', 'page', CARTFLOWS_STEP_POST_TYPE ) ); } } } /** * Kicking this off by calling 'get_instance()' method */ Cartflows_Permalink::get_instance(); flow/classes/class-cartflows-step-post-type.php000066600000031031152100564630015707 0ustar00post_type ) { /** * Remove Next/Prev Navigation * add_filter('next_post_link', '__return_empty_string'); * add_filter('previous_post_link', '__return_empty_string'); * * $page = locate_template( array( 'page.php' ) ); * * if ( ! empty( $page ) ) { * return $page; * } */ /* Remove Next / Previous Rel Link */ remove_action( 'wp_head', 'adjacent_posts_rel_link_wp_head', 10, 0 ); add_filter( 'next_post_rel_link', '__return_empty_string' ); add_filter( 'previous_post_rel_link', '__return_empty_string' ); $page_template = get_post_meta( _get_wcf_step_id(), '_wp_page_template', true ); $page_template = apply_filters( 'cartflows_page_template', $page_template ); $file = ''; switch ( $page_template ) { case 'cartflows-default': $file = CARTFLOWS_FLOW_DIR . 'templates/template-default.php'; $this->body_classes[] = $page_template; break; case 'cartflows-canvas': $file = CARTFLOWS_FLOW_DIR . 'templates/template-canvas.php'; $this->body_classes[] = $page_template; break; default: /** * Remove Next/Prev Navigation */ add_filter( 'next_post_link', '__return_empty_string' ); add_filter( 'previous_post_link', '__return_empty_string' ); $page = locate_template( array( 'page.php' ) ); if ( ! empty( $page ) ) { $file = $page; } break; /** * Default: * $file = CARTFLOWS_FLOW_DIR . 'templates/template-default.php'; * $this->body_classes[] = 'cartflows-default'; * break; */ } // Just to be safe, we check if the file exist first. if ( file_exists( $file ) ) { /* Add Body Class */ add_filter( 'body_class', array( $this, 'body_class' ) ); return $file; } else { echo $file; } } return $template; } /** * Body classes. * * @since 1.0.0 * @param array $classes Body classes. * @return array */ public function body_class( $classes = array() ) { $classes = array_merge( $classes, $this->body_classes ); return $classes; } /** * Create custom post type */ public function step_post_type() { $labels = array( 'name' => esc_html_x( 'Steps', 'flow step general name', 'cartflows' ), 'singular_name' => esc_html_x( 'Step', 'flow step singular name', 'cartflows' ), 'search_items' => esc_html__( 'Search Steps', 'cartflows' ), 'all_items' => esc_html__( 'All Steps', 'cartflows' ), 'edit_item' => esc_html__( 'Edit Step', 'cartflows' ), 'view_item' => esc_html__( 'View Step', 'cartflows' ), 'add_new' => esc_html__( 'Add New', 'cartflows' ), 'update_item' => esc_html__( 'Update Step', 'cartflows' ), 'add_new_item' => esc_html__( 'Add New', 'cartflows' ), 'new_item_name' => esc_html__( 'New Step Name', 'cartflows' ), ); $permalink_settings = Cartflows_Helper::get_permalink_settings(); $args = array( 'labels' => $labels, 'public' => true, 'query_var' => true, 'can_export' => true, 'exclude_from_search' => true, 'show_ui' => true, 'show_in_menu' => false, 'show_in_admin_bar' => true, 'supports' => array( 'title', 'editor', 'elementor', 'revisions' ), 'capability_type' => 'post', 'capabilities' => array( 'create_posts' => 'do_not_allow', // Prior to Wordpress 4.5, this was false. ), 'map_meta_cap' => true, ); if ( isset( $permalink_settings['permalink_structure'] ) && ! empty( $permalink_settings['permalink_structure'] ) ) { $args['rewrite'] = array( 'slug' => $permalink_settings['permalink_structure'], 'with_front' => false, ); } elseif ( isset( $permalink_settings['permalink'] ) && ! empty( $permalink_settings['permalink'] ) ) { $args['rewrite'] = array( 'slug' => $permalink_settings['permalink'], 'with_front' => false, ); } register_post_type( CARTFLOWS_STEP_POST_TYPE, $args ); // Step Type. $args = array( 'label' => __( 'Step Type', 'cartflows' ), 'public' => false, 'rewrite' => false, 'hierarchical' => false, ); register_taxonomy( CARTFLOWS_TAXONOMY_STEP_TYPE, CARTFLOWS_STEP_POST_TYPE, $args ); // Step Flow. $args = array( 'label' => __( 'Step Flow', 'cartflows' ), 'public' => false, 'rewrite' => false, 'hierarchical' => false, ); register_taxonomy( CARTFLOWS_TAXONOMY_STEP_FLOW, CARTFLOWS_STEP_POST_TYPE, $args ); if ( is_admin() ) { /** * Register 'Elementor' & 'Beaver Builder' site types. * * @see self::add_terms(); */ $taxonomy = CARTFLOWS_TAXONOMY_STEP_TYPE; $terms = array( array( 'name' => __( 'Landing', 'cartflows' ), 'slug' => 'landing', 'args' => array( 'slug' => 'landing', ), ), array( 'name' => __( 'Optin (Woo)', 'cartflows' ), 'slug' => 'optin', 'args' => array( 'slug' => 'optin', ), ), array( 'name' => __( 'Checkout (Woo)', 'cartflows' ), 'slug' => 'checkout', 'args' => array( 'slug' => 'checkout', ), ), array( 'name' => __( 'Thank You (Woo)', 'cartflows' ), 'slug' => 'thankyou', 'args' => array( 'slug' => 'thankyou', ), ), array( 'name' => __( 'Upsell (Woo)', 'cartflows' ), 'slug' => 'upsell', 'args' => array( 'slug' => 'upsell', ), ), array( 'name' => __( 'Downsell (Woo)', 'cartflows' ), 'slug' => 'downsell', 'args' => array( 'slug' => 'downsell', ), ), ); $this->add_terms( $taxonomy, $terms ); } } /** * Add WordPress templates. * * Adds Cartflows templates to steps * * @since 1.0.0 * @access public */ public function add_wp_templates_support() { add_filter( 'theme_' . CARTFLOWS_STEP_POST_TYPE . '_templates', array( $this, 'add_page_templates' ), 99, 4 ); } /** * Add page templates. * * @since 1.0.0 * @access public * * @param array $page_templates Array of page templates. * * @param object $wp_theme wp theme. * @param object $post post. * * @return array Page templates. */ public function add_page_templates( $page_templates, $wp_theme, $post ) { $page_templates = array( 'cartflows-default' => _x( 'CartFlows — Boxed', 'cartflows' ), 'cartflows-canvas' => _x( 'Template for Page Builders', 'cartflows' ), ); return $page_templates; } /** * Query fixe throwing error on 404 page due our post type changes. * We are setting post_type as empty array to fix the issue. * Ther error was throwing due to redirect_canonical function * This fix is apply for 404 page only */ public function query_fix() { global $wp_query; if ( $wp_query->is_404() ) { $wp_query->set( 'post_type', array() ); } } /** * Prevent slug duplicated * * @param string $slug post slug. * @param int $post_ID post id. * @param string $post_status post status. * @param string $post_type post type. * @param int $post_parent post parent id. * @param string $original_slug original slug. * @return string */ public function prevent_slug_duplicates( $slug, $post_ID, $post_status, $post_type, $post_parent, $original_slug ) { $check_post_types = array( 'post', 'page', CARTFLOWS_STEP_POST_TYPE, ); if ( ! in_array( $post_type, $check_post_types, true ) ) { return $slug; } if ( CARTFLOWS_STEP_POST_TYPE == $post_type ) { // Saving a post, check for duplicates in POST or PAGE post types. $post_match = get_page_by_path( $slug, 'OBJECT', 'post' ); $page_match = get_page_by_path( $slug, 'OBJECT', 'page' ); if ( $post_match || $page_match ) { $slug .= '-2'; } } else { // Saving a POST or PAGE, check for duplicates in CARTFLOWS_STEP_POST_TYPE post type. $custom_post_type_match = get_page_by_path( $slug, 'OBJECT', CARTFLOWS_STEP_POST_TYPE ); if ( $custom_post_type_match ) { $slug .= '-2'; } } return $slug; } /** * Add Update messages for any custom post type * * @param array $messages Array of default messages. */ public function post_update_messages( $messages ) { $custom_post_type = get_post_type( get_the_ID() ); if ( CARTFLOWS_STEP_POST_TYPE == $custom_post_type ) { $obj = get_post_type_object( $custom_post_type ); $singular_name = $obj->labels->singular_name; $messages[ $custom_post_type ] = array( 0 => '', // Unused. Messages start at index 1. /* translators: %s: singular custom post type name */ 1 => sprintf( __( '%s updated.', 'cartflows' ), $singular_name ), /* translators: %s: singular custom post type name */ 2 => sprintf( __( 'Custom %s updated.', 'cartflows' ), $singular_name ), /* translators: %s: singular custom post type name */ 3 => sprintf( __( 'Custom %s deleted.', 'cartflows' ), $singular_name ), /* translators: %s: singular custom post type name */ 4 => sprintf( __( '%s updated.', 'cartflows' ), $singular_name ), /* translators: %1$s: singular custom post type name ,%2$s: date and time of the revision */ 5 => isset( $_GET['revision'] ) ? sprintf( __( '%1$s restored to revision from %2$s', 'cartflows' ), $singular_name, wp_post_revision_title( (int) $_GET['revision'], false ) ) : false, //phpcs:ignore /* translators: %s: singular custom post type name */ 6 => sprintf( __( '%s published.', 'cartflows' ), $singular_name ), /* translators: %s: singular custom post type name */ 7 => sprintf( __( '%s saved.', 'cartflows' ), $singular_name ), /* translators: %s: singular custom post type name */ 8 => sprintf( __( '%s submitted.', 'cartflows' ), $singular_name ), /* translators: %s: singular custom post type name */ 9 => sprintf( __( '%s scheduled for.', 'cartflows' ), $singular_name ), /* translators: %s: singular custom post type name */ 10 => sprintf( __( '%s draft updated.', 'cartflows' ), $singular_name ), ); } return $messages; } /** * Add Terms for Taxonomy. * * => Example. * * $taxonomy = '{taxonomy}'; * $terms = array( * array( * 'name' => 'Landing', * 'slug' => 'landing', * ), * array( * 'name' => 'Checkout', * 'slug' => 'checkout', * ), * ); * * self::add_terms( $taxonomy, $terms ); * * @since 1.0.0 * @param string $taxonomy Taxonomy Name. * @param array $terms Terms list. * @return void */ public function add_terms( $taxonomy = '', $terms = array() ) { foreach ( $terms as $key => $term ) { $term_exist = term_exists( $term['slug'], $taxonomy ); if ( empty( $term_exist ) ) { /** * Add additional args if passed from request. * * @see https://codex.wordpress.org/Function_Reference/wp_insert_term */ if ( array_key_exists( 'args', $term ) ) { wp_insert_term( $term['name'], $taxonomy, $term['args'] ); } else { $term['args'] = array( $term['slug'] ); wp_insert_term( $term['name'], $taxonomy, $term['args'] ); } } } } } /** * Kicking this off by calling 'get_instance()' method */ Cartflows_Step_Post_Type::get_instance(); flow/classes/class-cartflows-flow-shortcodes.php000066600000006533152100564630016125 0ustar00post_type ) { $navigation = false; $step_id = intval( $post->ID ); $flow_id = get_post_meta( $step_id, 'wcf-flow-id', true ); if ( ! $flow_id ) { return $output; } $steps = get_post_meta( $flow_id, 'wcf-steps', true ); if ( ! is_array( $steps ) || ( is_array( $steps ) && empty( $steps ) ) ) { return $output; } 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 = get_permalink( $navigation['id'] ); } } return $output; } /** * Navigation shortcode callback * * @param array $atts attributes for shortcode. * @return string */ public function navigation_shortcode( $atts ) { $atts = shortcode_atts( array( 'label' => '', 'icon' => '', 'icon_position' => '', ), $atts ); global $post; $output = ''; if ( $post && CARTFLOWS_STEP_POST_TYPE === $post->post_type ) { $navigation = false; $step_id = intval( $post->ID ); $flow_id = get_post_meta( $step_id, 'wcf-flow-id', true ); if ( ! $flow_id ) { return $output; } $steps = get_post_meta( $flow_id, 'wcf-steps', true ); if ( ! is_array( $steps ) || ( is_array( $steps ) && empty( $steps ) ) ) { return $output; } 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 ) ) { $label = ( '' != $atts['label'] ) ? $atts['label'] : __( 'Next Step', 'cartflows' ); $before = ''; $after = ''; if ( '' != $atts['icon'] ) { if ( '' != $atts['icon_position'] ) { if ( 'before' == $atts['icon_position'] ) { $before = ''; } else { $after = ''; } } } $output = '
' . $before . $label . $after . '
'; } } return $output; } } /** * Kicking this off by calling 'get_instance()' method */ Cartflows_Flow_Shortcodes::get_instance(); flow/classes/class-cartflows-flow-loader.php000066600000002105152100564630015205 0ustar00include_files(); } /** * Load classes. * * @since 1.0.0 * * @return void */ public function include_files() { require_once CARTFLOWS_FLOW_DIR . 'classes/class-cartflows-flow-post-type.php'; require_once CARTFLOWS_FLOW_DIR . 'classes/class-cartflows-step-post-type.php'; require_once CARTFLOWS_FLOW_DIR . 'classes/class-cartflows-step-post-meta.php'; require_once CARTFLOWS_FLOW_DIR . 'classes/class-cartflows-flow-shortcodes.php'; require_once CARTFLOWS_FLOW_DIR . 'classes/class-cartflows-permalink.php'; } } /** * Kicking this off by calling 'get_instance()' method */ Cartflows_Flow_Loader::get_instance(); flow/templates/template-default.php000066600000001672152100564630013473 0ustar00 class="no-js"> >
>
class="no-js"> >
>
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-thankyou-step-meta', 'nonce-thankyou-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 ); /** * Get options */ $thankyou_data = array(); foreach ( $meta as $key => $value ) { $thankyou_data[ $key ] = $meta[ $key ]['default']; } do_action( 'wcf_thankyou_settings_markup_before', $meta ); $this->page_header_tab( $thankyou_data, $post->ID ); do_action( 'wcf_thankyou_settings_markup_after', $meta ); } /** * Page Header Tabs * * @param array $options Post meta. * @param int $post_id Post ID. */ public function page_header_tab( $options, $post_id ) { $active_tab = get_post_meta( $post_id, 'wcf-active-tab', true ); if ( empty( $active_tab ) ) { $active_tab = 'wcf-thankyou-shortcodes'; } $tabs = array( array( 'title' => __( 'Shortcodes', 'cartflows' ), 'id' => 'wcf-thankyou-shortcodes', 'class' => 'wcf-thankyou-shortcodes' === $active_tab ? 'wcf-tab wp-ui-text-highlight active' : 'wcf-tab', 'icon' => 'dashicons-editor-code', ), array( 'title' => __( 'Design', 'cartflows' ), 'id' => 'wcf-thankyou-design', 'class' => 'wcf-thankyou-design' === $active_tab ? 'wcf-tab wp-ui-text-highlight active' : 'wcf-tab', 'icon' => 'dashicons-admin-customizer', ), array( 'title' => __( 'Edit Fields', 'cartflows' ), 'id' => 'wcf-thankyou-fields', 'class' => 'wcf-thankyou-fields' === $active_tab ? 'wcf-tab wp-ui-text-highlight active' : 'wcf-tab', 'icon' => 'dashicons-welcome-widgets-menus', ), array( 'title' => __( 'Settings', 'cartflows' ), 'id' => 'wcf-thankyou-redirect', 'class' => 'wcf-thankyou-redirect' === $active_tab ? 'wcf-tab wp-ui-text-highlight active' : 'wcf-tab', 'icon' => 'dashicons-randomize', ), array( 'title' => __( 'Custom Script', 'cartflows' ), 'id' => 'wcf-thankyou-custom-script-header', 'class' => 'wcf-thankyou-custom-script-header' === $active_tab ? 'wcf-tab wp-ui-text-highlight active' : 'wcf-tab', 'icon' => 'dashicons-format-aside', ), ); ?>
$tab ) { ?>
meta->get_shortcode_field( array( 'label' => __( 'Order Details', 'cartflows' ), 'name' => 'wcf-order-details', 'content' => esc_html( '[cartflows_order_details]' ), ) ); ?>
meta->get_section( array( 'label' => __( 'Text', 'cartflows' ), ) ); echo wcf()->meta->get_color_picker_field( array( 'label' => __( 'Color', 'cartflows' ), 'name' => 'wcf-tq-text-color', 'value' => $options['wcf-tq-text-color'], ) ); echo wcf()->meta->get_font_family_field( array( 'for' => 'wcf-tq-font-family', 'label' => esc_html__( 'Font Family', 'cartflows' ), 'name' => 'wcf-tq-font-family', 'value' => $options['wcf-tq-font-family'], ) ); echo wcf()->meta->get_number_field( array( 'label' => __( 'Font Size', 'cartflows' ), 'name' => 'wcf-tq-font-size', 'value' => $options['wcf-tq-font-size'], ) ); echo wcf()->meta->get_section( array( 'label' => __( 'Heading', 'cartflows' ), ) ); echo wcf()->meta->get_color_picker_field( array( 'label' => __( 'Color', 'cartflows' ), 'name' => 'wcf-tq-heading-color', 'value' => $options['wcf-tq-heading-color'], ) ); echo wcf()->meta->get_font_family_field( array( 'for' => 'wcf-tq-heading-font-family', 'label' => esc_html__( 'Font Family', 'cartflows' ), 'name' => 'wcf-tq-heading-font-family', 'value' => $options['wcf-tq-heading-font-family'], ) ); echo wcf()->meta->get_font_weight_field( array( 'for' => 'wcf-tq-heading-font-family', 'label' => esc_html__( 'Font Weight', 'cartflows' ), 'name' => 'wcf-tq-heading-font-wt', 'value' => $options['wcf-tq-heading-font-wt'], ) ); echo wcf()->meta->get_checkbox_field( array( 'label' => __( 'Advanced Options', 'cartflows' ), 'name' => 'wcf-tq-advance-options-fields', 'value' => $options['wcf-tq-advance-options-fields'], 'after' => 'Enable', ) ); echo wcf()->meta->get_number_field( array( 'for' => 'wcf-heading', 'label' => esc_html__( 'Container Width (In px)', 'cartflows' ), 'name' => 'wcf-tq-container-width', 'value' => $options['wcf-tq-container-width'], ) ); echo wcf()->meta->get_color_picker_field( array( 'label' => __( 'Section Background Color', 'cartflows' ), 'name' => 'wcf-tq-section-bg-color', 'value' => $options['wcf-tq-section-bg-color'], ) ); ?>
meta->get_checkbox_field( array( 'name' => 'wcf-show-overview-section', 'value' => $options['wcf-show-overview-section'], 'after' => esc_html__( 'Enable Order Overview ', 'cartflows' ), ) ); echo wcf()->meta->get_checkbox_field( array( 'name' => 'wcf-show-details-section', 'value' => $options['wcf-show-details-section'], 'after' => esc_html__( 'Enable Order Details ', 'cartflows' ), ) ); echo wcf()->meta->get_checkbox_field( array( 'name' => 'wcf-show-billing-section', 'value' => $options['wcf-show-billing-section'], 'after' => esc_html__( 'Enable Billing Details ', 'cartflows' ), ) ); echo wcf()->meta->get_checkbox_field( array( 'name' => 'wcf-show-shipping-section', 'value' => $options['wcf-show-shipping-section'], 'after' => esc_html__( 'Enable Shipping Details ', 'cartflows' ), ) ); echo wcf()->meta->get_hidden_field( array( 'name' => 'wcf-field-google-font-url', 'value' => $options['wcf-field-google-font-url'], ) ); ?>
meta->get_text_field( array( 'label' => __( 'Thank You Page Text', 'cartflows' ), 'name' => 'wcf-tq-text', 'value' => $options['wcf-tq-text'], 'attr' => array( 'placeholder' => __( 'Thank you. Your order has been received.', 'cartflows' ), ), 'help' => __( 'It will change the default text on thank you page.', 'cartflows' ), ) ); echo wcf()->meta->get_hr_line_field( array() ); echo wcf()->meta->get_checkbox_field( array( 'label' => __( 'Redirect After Purchase', 'cartflows' ), 'name' => 'wcf-show-tq-redirect-section', 'value' => $options['wcf-show-tq-redirect-section'], 'after' => 'Enable', ) ); echo wcf()->meta->get_text_field( array( 'label' => __( 'Redirect Link', 'cartflows' ), 'name' => 'wcf-tq-redirect-link', 'value' => $options['wcf-tq-redirect-link'], 'attr' => array( 'placeholder' => __( 'https://', 'cartflows' ), ), ) ); ?>
tab_custom_script( $options, $post_id ); ?> right_column_footer( $options, $post_id ); ?>
options->get_thankyou_fields( $post_id ); } return self::$meta_option; } /** * Metabox Save * * @param number $post_id Post ID. * @return void */ public function save_meta_box( $post_id ) { // Checks save status. $is_autosave = wp_is_post_autosave( $post_id ); $is_revision = wp_is_post_revision( $post_id ); $is_valid_nonce = ( isset( $_POST['nonce-thankyou-step-meta'] ) && wp_verify_nonce( sanitize_text_field( wp_unslash( $_POST['nonce-thankyou-step-meta'] ) ), 'save-nonce-thankyou-step-meta' ) ) ? true : false; // Exits script depending on save status. if ( $is_autosave || $is_revision || ! $is_valid_nonce ) { return; } wcf()->options->save_thankyou_fields( $post_id ); } } /** * Kicking this off by calling 'get_instance()' method */ Cartflows_Thankyou_Meta::get_instance(); thankyou/classes/class-cartflows-thankyou-markup.php000066600000023422152100564630017031 0ustar00ID; $enable_redirection = wcf()->options->get_thankyou_meta_value( $thank_you_id, 'wcf-show-tq-redirect-section' ); $redirect_link = wp_http_validate_url( wcf()->options->get_thankyou_meta_value( $thank_you_id, 'wcf-tq-redirect-link' ) ); if ( 'yes' === $enable_redirection && ! empty( $redirect_link ) ) { exit( wp_redirect( $redirect_link ) ); //phpcs:ignore } } } /** * Order shortcode markup * * @param array $atts attributes. * @since 1.0.0 */ public function cartflows_order_details_shortcode_markup( $atts ) { $output = ''; if ( _is_wcf_thankyou_type() ) { /* Remove order item link */ add_filter( 'woocommerce_order_item_permalink', '__return_false' ); /* Change order text */ add_filter( 'woocommerce_thankyou_order_received_text', array( $this, 'custom_tq_text' ), 10, 2 ); if ( ! function_exists( 'wc_print_notices' ) ) { $notice_out = '

' . __( '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 "
"; wc_get_template( 'checkout/thankyou.php', array( 'order' => $order ) ); echo '
'; $output = ob_get_clean(); } return $output; } /** * Load Thank You scripts. * * @return void */ public function thank_you_scripts() { if ( _is_wcf_thankyou_type() ) { do_action( 'cartflows_thank_you_scripts' ); $style = $this->generate_thank_you_style(); wp_add_inline_style( 'wcf-frontend-global', $style ); } } /** * Load DIVI compatibility Thank You style. * * @return void */ public function add_divi_compatibility_css() { global $post; $thank_you_id = $post->ID; if ( Cartflows_Compatibility::get_instance()->is_divi_enabled() || Cartflows_Compatibility::get_instance()->is_divi_builder_enabled( $thank_you_id ) ) { wp_enqueue_style( 'wcf-frontend-global-divi', wcf()->utils->get_css_url( 'frontend-divi' ), array(), CARTFLOWS_VER ); } } /** * Set thank you as a order received page. * * @param boolean $is_order_page order page. * @return boolean */ public function set_order_received_page( $is_order_page ) { if ( _is_wcf_thankyou_type() ) { $is_order_page = true; } return $is_order_page; } /** * Generate Thank You Styles. * * @return string */ public function generate_thank_you_style() { global $post; if ( _is_wcf_thankyou_type() ) { $thank_you_id = $post->ID; } else { $thank_you_id = _get_wcf_thankyou_id( $post->post_content ); } CartFlows_Font_Families::render_fonts( $thank_you_id ); $text_color = wcf()->options->get_thankyou_meta_value( $thank_you_id, 'wcf-tq-text-color' ); $text_font_family = wcf()->options->get_thankyou_meta_value( $thank_you_id, 'wcf-tq-font-family' ); $text_font_size = wcf()->options->get_thankyou_meta_value( $thank_you_id, 'wcf-tq-font-size' ); $heading_text_color = wcf()->options->get_thankyou_meta_value( $thank_you_id, 'wcf-tq-heading-color' ); $heading_font_family = wcf()->options->get_thankyou_meta_value( $thank_you_id, 'wcf-tq-heading-font-family' ); $heading_font_weight = wcf()->options->get_thankyou_meta_value( $thank_you_id, 'wcf-tq-heading-font-wt' ); $container_width = wcf()->options->get_thankyou_meta_value( $thank_you_id, 'wcf-tq-container-width' ); $section_bg_color = wcf()->options->get_thankyou_meta_value( $thank_you_id, 'wcf-tq-section-bg-color' ); $show_order_review = wcf()->options->get_thankyou_meta_value( $thank_you_id, 'wcf-show-overview-section' ); $show_order_details = wcf()->options->get_thankyou_meta_value( $thank_you_id, 'wcf-show-details-section' ); $show_billing_details = wcf()->options->get_thankyou_meta_value( $thank_you_id, 'wcf-show-billing-section' ); $show_shipping_details = wcf()->options->get_thankyou_meta_value( $thank_you_id, 'wcf-show-shipping-section' ); $output = " .wcf-thankyou-wrap{ color: {$text_color}; font-family: {$text_font_family}; max-width:{$container_width}px; font-size: {$text_font_size}px; } .woocommerce-order h2.woocommerce-column__title, .woocommerce-order h2.woocommerce-order-details__title, .woocommerce-order .woocommerce-thankyou-order-received, .woocommerce-order-details h2, .woocommerce-order h2.wc-bacs-bank-details-heading, .woocommerce-order h2.woocommerce-order-downloads__title { color: {$heading_text_color}; font-family: {$heading_font_family}; font-weight: {$heading_font_weight}; } .woocommerce-order ul.order_details, .woocommerce-order .woocommerce-order-details, .woocommerce-order .woocommerce-customer-details, .woocommerce-order .woocommerce-bacs-bank-details, .woocommerce-order .woocommerce-order-downloads{ background-color: {$section_bg_color} } img.emoji, img.wp-smiley {} "; if ( 'no' == $show_order_review ) { $output .= ' .woocommerce-order ul.order_details{ display: none; } '; } if ( 'no' == $show_order_details ) { $output .= ' .woocommerce-order .woocommerce-order-details{ display: none; } '; } if ( 'no' == $show_billing_details ) { $output .= ' .woocommerce-order .woocommerce-customer-details .woocommerce-column--billing-address{ display: none; } '; } if ( 'no' == $show_shipping_details ) { $output .= ' .woocommerce-order .woocommerce-customer-details .woocommerce-column--shipping-address{ display: none; } '; } if ( 'no' == $show_billing_details && 'no' == $show_shipping_details ) { $output .= ' .woocommerce-order .woocommerce-customer-details{ display: none; } '; } return $output; } /** * Set as a checkout page if it is thank you page. * Thank you page need to be set as a checkout page. * Becauye ayment gateways will not load if it is not checkout. * * @param bool $is_checkout is checkout. * * @return bool */ public function woo_checkout_flag( $is_checkout ) { if ( ! is_admin() ) { if ( _is_wcf_thankyou_type() ) { $is_checkout = true; } } return $is_checkout; } /** * Add custom text on thank you page. * * @param string $woo_text Default text. * @param int $order order. */ public function custom_tq_text( $woo_text, $order ) { global $post; $thank_you_id = $post->ID; $new_text = wcf()->options->get_thankyou_meta_value( $thank_you_id, 'wcf-tq-text' ); if ( ! empty( $new_text ) ) { $woo_text = do_shortcode( $new_text ); } return $woo_text; } } /** * Kicking this off by calling 'get_instance()' method */ Cartflows_Thankyou_Markup::get_instance(); thankyou/class-cartflows-thankyou.php000066600000001630152100564630014074 0ustar00