class-cartflows-thankyou.php000066600000001630152141652650012237 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-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(); classes/class-cartflows-thankyou-markup.php000066600000023422152141652650015174 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();