registered['jquery-ui-core']->ver ) ? $wp_scripts->registered['jquery-ui-core']->ver : '1.9.2'; $locale = localeconv(); $decimal = isset( $locale['decimal_point'] ) ? $locale['decimal_point'] : '.'; wp_enqueue_style( 'woocommerce_admin_menu_styles', WC()->plugin_url() . '/assets/css/menu.css', array(), WC()->version ); wp_enqueue_style( 'woocommerce_admin_styles', WC()->plugin_url() . '/assets/css/admin.css', array(), WC()->version ); if ( ! wp_style_is( 'jquery-ui-style', 'registered' ) ) { wp_register_style( 'jquery-ui-style', WC()->plugin_url() . '/assets/css/jquery-ui/jquery-ui' . $suffix . '.css', array(), WC()->version ); } if ( ! wp_style_is( 'jquery-ui-style' ) ) { wp_enqueue_style( 'jquery-ui-style' ); } $woocommerce_admin_params = array( /* translators: Decimal point */ 'i18n_decimal_error' => sprintf( __( 'Please enter in decimal (%s) format without thousand separators.', 'woocommerce-smart-coupons' ), $decimal ), /* translators: Decimal point */ 'i18n_mon_decimal_error' => sprintf( __( 'Please enter in monetary decimal (%s) format without thousand separators and currency symbols.', 'woocommerce-smart-coupons' ), wc_get_price_decimal_separator() ), 'i18n_country_iso_error' => __( 'Please enter in country code with two capital letters.', 'woocommerce-smart-coupons' ), 'i18_sale_less_than_regular_error' => __( 'Please enter in a value less than the regular price.', 'woocommerce-smart-coupons' ), 'decimal_point' => $decimal, 'mon_decimal_point' => wc_get_price_decimal_separator(), 'strings' => array( 'import_products' => __( 'Import', 'woocommerce-smart-coupons' ), 'export_products' => __( 'Export', 'woocommerce-smart-coupons' ), ), 'urls' => array( 'import_products' => esc_url_raw( admin_url( 'edit.php?post_type=product&page=product_importer' ) ), 'export_products' => esc_url_raw( admin_url( 'edit.php?post_type=product&page=product_exporter' ) ), ), ); $woocommerce_admin_meta_boxes_params = array( 'remove_item_notice' => __( 'Are you sure you want to remove the selected items? If you have previously reduced this item\'s stock, or this order was submitted by a customer, you will need to manually restore the item\'s stock.', 'woocommerce-smart-coupons' ), 'i18n_select_items' => __( 'Please select some items.', 'woocommerce-smart-coupons' ), 'i18n_do_refund' => __( 'Are you sure you wish to process this refund? This action cannot be undone.', 'woocommerce-smart-coupons' ), 'i18n_delete_refund' => __( 'Are you sure you wish to delete this refund? This action cannot be undone.', 'woocommerce-smart-coupons' ), 'i18n_delete_tax' => __( 'Are you sure you wish to delete this tax column? This action cannot be undone.', 'woocommerce-smart-coupons' ), 'remove_item_meta' => __( 'Remove this item meta?', 'woocommerce-smart-coupons' ), 'remove_attribute' => __( 'Remove this attribute?', 'woocommerce-smart-coupons' ), 'name_label' => __( 'Name', 'woocommerce-smart-coupons' ), 'remove_label' => __( 'Remove', 'woocommerce-smart-coupons' ), 'click_to_toggle' => __( 'Click to toggle', 'woocommerce-smart-coupons' ), 'values_label' => __( 'Value(s)', 'woocommerce-smart-coupons' ), 'text_attribute_tip' => __( 'Enter some text, or some attributes by pipe (|) separating values.', 'woocommerce-smart-coupons' ), 'visible_label' => __( 'Visible on the product page', 'woocommerce-smart-coupons' ), 'used_for_variations_label' => __( 'Used for variations', 'woocommerce-smart-coupons' ), 'new_attribute_prompt' => __( 'Enter a name for the new attribute term:', 'woocommerce-smart-coupons' ), 'calc_totals' => __( 'Calculate totals based on order items, discounts, and shipping?', 'woocommerce-smart-coupons' ), 'calc_line_taxes' => __( 'Calculate line taxes? This will calculate taxes based on the customers country. If no billing/shipping is set it will use the store base country.', 'woocommerce-smart-coupons' ), 'copy_billing' => __( 'Copy billing information to shipping information? This will remove any currently entered shipping information.', 'woocommerce-smart-coupons' ), 'load_billing' => __( 'Load the customer\'s billing information? This will remove any currently entered billing information.', 'woocommerce-smart-coupons' ), 'load_shipping' => __( 'Load the customer\'s shipping information? This will remove any currently entered shipping information.', 'woocommerce-smart-coupons' ), 'featured_label' => __( 'Featured', 'woocommerce-smart-coupons' ), 'prices_include_tax' => esc_attr( get_option( 'woocommerce_prices_include_tax' ) ), 'round_at_subtotal' => esc_attr( get_option( 'woocommerce_tax_round_at_subtotal' ) ), 'no_customer_selected' => __( 'No customer selected', 'woocommerce-smart-coupons' ), 'plugin_url' => WC()->plugin_url(), 'ajax_url' => admin_url( 'admin-ajax.php' ), 'order_item_nonce' => wp_create_nonce( 'order-item' ), 'add_attribute_nonce' => wp_create_nonce( 'add-attribute' ), 'save_attributes_nonce' => wp_create_nonce( 'save-attributes' ), 'calc_totals_nonce' => wp_create_nonce( 'calc-totals' ), 'get_customer_details_nonce' => wp_create_nonce( 'get-customer-details' ), 'search_products_nonce' => wp_create_nonce( 'search-products' ), 'grant_access_nonce' => wp_create_nonce( 'grant-access' ), 'revoke_access_nonce' => wp_create_nonce( 'revoke-access' ), 'add_order_note_nonce' => wp_create_nonce( 'add-order-note' ), 'delete_order_note_nonce' => wp_create_nonce( 'delete-order-note' ), 'calendar_image' => WC()->plugin_url() . '/assets/images/calendar.png', 'post_id' => '', 'base_country' => WC()->countries->get_base_country(), 'currency_format_num_decimals' => wc_get_price_decimals(), 'currency_format_symbol' => get_woocommerce_currency_symbol(), 'currency_format_decimal_sep' => esc_attr( wc_get_price_decimal_separator() ), 'currency_format_thousand_sep' => esc_attr( wc_get_price_thousand_separator() ), 'currency_format' => esc_attr( str_replace( array( '%1$s', '%2$s' ), array( '%s', '%v' ), get_woocommerce_price_format() ) ), // For accounting JS. 'rounding_precision' => WC_ROUNDING_PRECISION, 'tax_rounding_mode' => WC_TAX_ROUNDING_MODE, 'product_types' => array_map( 'sanitize_title', get_terms( 'product_type', array( 'hide_empty' => false, 'fields' => 'names', ) ) ), 'i18n_download_permission_fail' => __( 'Could not grant access - the user may already have permission for this file or billing email is not set. Ensure the billing email is set, and the order has been saved.', 'woocommerce-smart-coupons' ), 'i18n_permission_revoke' => __( 'Are you sure you want to revoke access to this download?', 'woocommerce-smart-coupons' ), 'i18n_tax_rate_already_exists' => __( 'You cannot add the same tax rate twice!', 'woocommerce-smart-coupons' ), 'i18n_product_type_alert' => __( 'Your product has variations! Before changing the product type, it is a good idea to delete the variations to avoid errors in the stock reports.', 'woocommerce-smart-coupons' ), ); if ( ! wp_script_is( 'wc-admin-coupon-meta-boxes' ) ) { wp_enqueue_script( 'wc-admin-coupon-meta-boxes', WC()->plugin_url() . '/assets/js/admin/meta-boxes-coupon' . $suffix . '.js', array( 'woocommerce_admin', 'wc-enhanced-select', 'wc-admin-meta-boxes' ), WC()->version, false ); } wp_localize_script( 'wc-admin-coupon-meta-boxes', 'woocommerce_admin_meta_boxes_coupon', array( 'generate_button_text' => esc_html__( 'Generate coupon code', 'woocommerce-smart-coupons' ), 'characters' => apply_filters( 'woocommerce_coupon_code_generator_characters', 'ABCDEFGHJKMNPQRSTUVWXYZ23456789' ), 'char_length' => apply_filters( 'woocommerce_coupon_code_generator_character_length', 8 ), 'prefix' => apply_filters( 'woocommerce_coupon_code_generator_prefix', '' ), 'suffix' => apply_filters( 'woocommerce_coupon_code_generator_suffix', '' ), ) ); wp_localize_script( 'wc-admin-meta-boxes', 'woocommerce_admin_meta_boxes', $woocommerce_admin_meta_boxes_params ); if ( ! wp_script_is( 'woocommerce_admin' ) ) { wp_enqueue_script( 'woocommerce_admin', WC()->plugin_url() . '/assets/js/admin/woocommerce_admin' . $suffix . '.js', array( 'jquery', 'jquery-blockui', 'jquery-ui-sortable', 'jquery-ui-widget', 'jquery-ui-core', 'jquery-tiptip' ), WC()->version, false ); } wp_localize_script( 'woocommerce_admin', 'woocommerce_admin', $woocommerce_admin_params ); } /** * Function to show import message */ public function woocommerce_show_import_message() { global $pagenow, $typenow; $get_show_import_message = ( ! empty( $_GET['show_import_message'] ) ) ? wc_clean( wp_unslash( $_GET['show_import_message'] ) ) : ''; // phpcs:ignore $get_imported = ( ! empty( $_GET['imported'] ) ) ? wc_clean( wp_unslash( $_GET['imported'] ) ) : 0; // phpcs:ignore $get_skipped = ( ! empty( $_GET['skipped'] ) ) ? wc_clean( wp_unslash( $_GET['skipped'] ) ) : 0; // phpcs:ignore if ( empty( $get_show_import_message ) ) { return; } if ( 'true' === $get_show_import_message ) { if ( 'edit.php' === $pagenow && 'shop_coupon' === $typenow ) { $imported = $get_imported; $skipped = $get_skipped; echo '

' . esc_html__( 'Import complete - imported', 'woocommerce-smart-coupons' ) . ' ' . esc_html( $imported ) . ', ' . esc_html__( 'skipped', 'woocommerce-smart-coupons' ) . ' ' . esc_html( $skipped ) . '

'; } } } /** * Function to include script in admin footer */ public function smart_coupons_script_in_footer() { global $pagenow; if ( empty( $pagenow ) ) { return; } $get_page = ( ! empty( $_GET['page'] ) ) ? wc_clean( wp_unslash( $_GET['page'] ) ) : ''; // phpcs:ignore $post_type = ( ! empty( $_GET['post_type'] ) ) ? wc_clean( wp_unslash( $_GET['post_type'] ) ) : ''; // phpcs:ignore if ( in_array( $get_page, array( 'wc-smart-coupons', 'sc-about', 'sc-faqs' ), true ) || 'shop_coupon' === $post_type ) { ?> coupons to your store via a csv file.', 'woocommerce-smart-coupons' ), array( $this, 'coupon_importer' ) ); } if ( 'sent_gift_certificate' === $get_action && 'wc-smart-coupons' === $get_page ) { $email = $post_smart_coupon_email; $amount = $post_smart_coupon_amount; $message = $post_smart_coupon_message; $this->send_gift_certificate( $email, $amount, $message ); } } /** * Function to process & send gift certificate * * @param string $email Comma separated email address. * @param float $amount Coupon amount. * @param string $message Optional. */ public function send_gift_certificate( $email, $amount, $message = '' ) { $emails = explode( ',', $email ); $location = add_query_arg( array( 'page' => 'wc-smart-coupons', 'tab' => 'send-smart-coupons', ), admin_url( 'admin.php' ) ); $validation_error = ''; // Check for valid amount. if ( ! $amount || ! is_numeric( $amount ) ) { $validation_error = 'amount_error'; } if ( empty( $validation_error ) ) { foreach ( $emails as $email ) { $email = sanitize_email( $email ); // Check for valid email address. if ( ( ! $email || ! is_email( $email ) ) ) { $validation_error = 'email_error'; break; } } } // Proceed to bulk generate if there isn't any validation error. if ( empty( $validation_error ) ) { // Set required $_POST data for bulk generate. $_POST['no_of_coupons_to_generate'] = count( $emails ); $_POST['discount_type'] = 'smart_coupon'; $_POST['smart_coupons_generate_action'] = 'send_store_credit'; // includes. require 'class-wc-sc-coupon-import.php'; require 'class-wc-sc-coupon-parser.php'; $coupon_importer = WC_SC_Coupon_Import::get_instance(); $action_processed = $coupon_importer->process_bulk_generate_action(); if ( false === $action_processed ) { $location = add_query_arg( array( 'process_error' => 'yes', ), $location ); } } elseif ( 'amount_error' === $validation_error ) { $location = add_query_arg( array( 'amount_error' => 'yes', ), $location ); } elseif ( 'email_error' === $validation_error ) { $location = add_query_arg( array( 'email_error' => 'yes', ), $location ); } if ( ! empty( $location ) ) { wp_safe_redirect( $location ); exit; } } /** * Function to perform importing of coupon from csv file */ public function coupon_importer() { if ( defined( 'WP_LOAD_IMPORTERS' ) ) { wp_safe_redirect( add_query_arg( array( 'page' => 'wc-smart-coupons', 'tab' => 'import-smart-coupons', ), admin_url( 'admin.php' ) ) ); exit; } // Load Importer API. require_once ABSPATH . 'wp-admin/includes/import.php'; if ( ! class_exists( 'WP_Importer' ) ) { $class_wp_importer = ABSPATH . 'wp-admin/includes/class-wp-importer.php'; if ( file_exists( $class_wp_importer ) ) { require $class_wp_importer; } } // includes. require 'class-wc-sc-coupon-import.php'; require 'class-wc-sc-coupon-parser.php'; $wc_csv_coupon_import = new WC_SC_Coupon_Import(); $wc_csv_coupon_import->dispatch(); } /** * Function to add submenu page for Coupon CSV Import */ public function woocommerce_coupon_admin_menu() { if ( $this->is_wc_gte_44() ) { add_submenu_page( 'woocommerce-marketing', __( 'Smart Coupon', 'woocommerce-smart-coupons' ), __( 'Smart Coupon', 'woocommerce-smart-coupons' ), 'manage_woocommerce', 'wc-smart-coupons', array( $this, 'admin_page' ) ); } else { add_submenu_page( 'woocommerce', __( 'Smart Coupon', 'woocommerce-smart-coupons' ), __( 'Smart Coupon', 'woocommerce-smart-coupons' ), 'manage_woocommerce', 'wc-smart-coupons', array( $this, 'admin_page' ) ); } } /** * Function to remove submenu link for Smart Coupons */ public function woocommerce_coupon_admin_head() { if ( $this->is_wc_gte_44() ) { remove_submenu_page( 'woocommerce-marketing', 'wc-smart-coupons' ); } else { remove_submenu_page( 'woocommerce', 'wc-smart-coupons' ); } } /** * Function to show content on the Coupon CSV Importer page */ public function admin_page() { global $store_credit_label; $tab = ( ! empty( $_GET['tab'] ) ? ( $_GET['tab'] == 'send-smart-coupons' ? 'send-smart-coupons' : 'import-smart-coupons' ) : 'generate_bulk_coupons' ); // phpcs:ignore ?>

admin_send_certificate(); break; case 'import-smart-coupons': $this->admin_import_page(); break; default: $this->admin_generate_bulk_coupons_and_export(); break; } ?>
dispatch(); } /** * Send Gift Certificate page content */ public function admin_send_certificate() { global $store_credit_label; $get_sent = ( ! empty( $_GET['sent'] ) ) ? wc_clean( wp_unslash( $_GET['sent'] ) ) : ''; // phpcs:ignore $get_email_error = ( ! empty( $_GET['email_error'] ) ) ? wc_clean( wp_unslash( $_GET['email_error'] ) ) : ''; // phpcs:ignore $get_amount_error = ( ! empty( $_GET['amount_error'] ) ) ? wc_clean( wp_unslash( $_GET['amount_error'] ) ) : ''; // phpcs:ignore $get_process_error = ( ! empty( $_GET['process_error'] ) ) ? wc_clean( wp_unslash( $_GET['process_error'] ) ) : ''; // phpcs:ignore if ( 'yes' === $get_sent ) { /* translators: %s: singular name for store credit */ $ack_message = ! empty( $store_credit_label['singular'] ) ? sprintf( esc_html__( '%s sent successfully.', 'woocommerce-smart-coupons' ), esc_html( ucfirst( $store_credit_label['singular'] ) ) ) : esc_html__( 'Store Credit / Gift Certificate sent successfully.', 'woocommerce-smart-coupons' ); echo '

' . esc_html( $ack_message ) . '

'; } elseif ( 'yes' === $get_process_error ) { /* translators: %s: singular name for store credit */ $error_message = ! empty( $store_credit_label['singular'] ) ? sprintf( esc_html__( 'There has been an error in sending %s.', 'woocommerce-smart-coupons' ), esc_html( ucfirst( $store_credit_label['singular'] ) ) ) : esc_html__( 'There has been an error in sending Store Credit / Gift Certificate.', 'woocommerce-smart-coupons' ); $error_message = $error_message . ' ' . esc_html__( 'Please try again later.', 'woocommerce-smart-coupons' ); echo '

' . esc_html( $error_message ) . '

'; } if ( ! wp_script_is( 'jquery' ) ) { wp_enqueue_script( 'jquery' ); } $message = ''; $editor_args = array( 'textarea_name' => 'smart_coupon_message', 'textarea_rows' => 10, 'editor_class' => 'wp-editor-message', 'media_buttons' => true, 'tinymce' => true, ); $editor_id = 'edit_smart_coupon_message'; ?> get_preview_email_js( $editor_id ); ?>

'wc-smart-coupons', 'tab' => 'import-smart-coupons', 'step' => '2', ), admin_url( 'admin.php' ) ); ?>

' . esc_html__( 'Invalid email address.', 'woocommerce-smart-coupons' ) . '

'; } ?>
' . esc_html( get_woocommerce_currency_symbol() ) . '', '  ' ); // phpcs:ignore ?>

' . esc_html__( 'Invalid amount.', 'woocommerce-smart-coupons' ) . '

'; } ?>

get_sample_coupon_code(); if ( ! empty( $coupon_code ) ) { ?>

get_preview_email_html( $coupon_code ); } } /** * Function to get sample coupon code */ public function get_sample_coupon_code() { global $wpdb; $coupon_code = wp_cache_get( 'wc_sc_any_coupon_code', 'woocommerce_smart_coupons' ); if ( false === $coupon_code ) { $coupon_code = $wpdb->get_var( // phpcs:ignore $wpdb->prepare( "SELECT post_title FROM $wpdb->posts AS p LEFT JOIN $wpdb->postmeta AS pm ON (p.ID = pm.post_id) WHERE post_type = %s AND ( pm.meta_key = %s AND pm.meta_value = %s ) LIMIT 1", 'shop_coupon', 'discount_type', 'smart_coupon' ) ); wp_cache_set( 'wc_sc_any_coupon_code', $coupon_code, 'woocommerce_smart_coupons' ); $this->maybe_add_cache_key( 'wc_sc_any_coupon_code' ); } if ( empty( $coupon_code ) ) { $args = array( 'return' => 'code', 'discount_type' => 'smart_coupon', 'amount' => 1.99, 'description' => __( 'This is a sample coupon', 'woocommerce_smart_coupons' ), 'date_expires' => $this->strtotime( '+20 years' ), 'email_restrictions' => array( get_option( 'admin_email' ) ), ); $coupon_code = $this->generate_coupon( $args ); $coupon = new WC_Coupon( $coupon_code ); $coupon_id = $this->is_callable( $coupon, 'get_id' ) ? $coupon->get_id() : 0; if ( ! empty( $coupon_id ) ) { $args = array( 'ID' => $coupon_id, 'post_status' => 'auto-draft', ); wp_update_post( $args ); // Because $coupon->set_status( 'auto-draft' ) not working. } } return $coupon_code; } /** * Function to get preview html for Coupon Emails * * @param string $coupon_code Coupon code. */ public function get_preview_email_html( $coupon_code = '' ) { ?> generate_unique_code() ); $reference_post_id = ( $this->is_callable( $coupon, 'save' ) ) ? $coupon->save() : 0; if ( ! empty( $reference_post_id ) ) { $args = array( 'ID' => $reference_post_id, 'post_status' => 'auto-draft', ); wp_update_post( $args ); // Because $coupon->set_status( 'draft' ) not working. update_option( 'empty_reference_smart_coupons', $reference_post_id, 'no' ); } } else { $reference_post_id = $empty_reference_coupon; } $post = get_post( $reference_post_id ); // phpcs:ignore if ( empty( $post ) ) { $coupon = new WC_Coupon( $this->generate_unique_code() ); $reference_post_id = ( $this->is_callable( $coupon, 'save' ) ) ? $coupon->save() : 0; if ( ! empty( $reference_post_id ) ) { $args = array( 'ID' => $reference_post_id, 'post_status' => 'auto-draft', ); wp_update_post( $args ); // Because $coupon->set_status( 'auto-draft' ) not working. update_option( 'empty_reference_smart_coupons', $reference_post_id, 'no' ); } $post = get_post( $reference_post_id ); // phpcs:ignore } if ( ! class_exists( 'WC_Meta_Box_Coupon_Data' ) ) { require_once WC()->plugin_path() . '/includes/admin/meta-boxes/class-wc-meta-box-coupon-data.php'; } if ( ! class_exists( 'WC_Admin_Post_Types' ) ) { require_once WC()->plugin_path() . '/includes/admin/class-wc-admin-post-types.php'; } $admin_post_types = new WC_Admin_Post_Types(); $is_post_generate_and_import = ( isset( $_POST['generate_and_import'] ) ) ? true : false; // phpcs:ignore $post_smart_coupons_generate_action = ( ! empty( $_POST['smart_coupons_generate_action'] ) ) ? wc_clean( wp_unslash( $_POST['smart_coupons_generate_action'] ) ) : ''; // phpcs:ignore $message = ''; $editor_args = array( 'textarea_name' => 'smart_coupon_message', 'textarea_rows' => 7, 'editor_class' => 'wp-editor-message', 'media_buttons' => true, 'tinymce' => true, ); $editor_id = 'edit_smart_coupon_message'; ?>

'wc-smart-coupons', 'tab' => 'import-smart-coupons', 'step' => '2', ), admin_url( 'admin.php' ) ); ?>

 

  'wc-smart-coupons', 'tab' => 'import-smart-coupons', ), admin_url( 'admin.php' ) ); ?> ' . esc_html__( 'import', 'woocommerce-smart-coupons' ) . ' ' . esc_html__( 'later', 'woocommerce-smart-coupons' ) . ')'; ?>

 

get_preview_email_js( $editor_id ); ?>

', '' ); ?>

ID ) && $this->is_hpos_order( $post->ID ) ) { $post_or_order = wc_get_order( $post->ID ); } else { $post_or_order = $post; } $admin_post_types->edit_form_after_title( $post_or_order ); ?>

'sc_coupon_category' ); $tax_name = esc_attr( $args['taxonomy'] ); $taxonomy = get_taxonomy( $args['taxonomy'] ); ?>
    ID, array( 'taxonomy' => $tax_name, 'popular_cats' => $popular_ids, ) ); ?>

query_vars['s'] ) ) { return; } if ( 'shop_coupon' !== $wp->query_vars['post_type'] ) { return; } $e = substr( $wp->query_vars['s'], 0, 5 ); if ( 'email:' === strtolower( substr( $wp->query_vars['s'], 0, 6 ) ) ) { $email = trim( substr( $wp->query_vars['s'], 6 ) ); if ( ! $email ) { return; } $post_ids = wp_cache_get( 'wc_sc_get_coupon_ids_by_email_' . sanitize_key( $email ), 'woocommerce_smart_coupons' ); if ( false === $post_ids ) { $post_ids = $wpdb->get_col( $wpdb->prepare( "SELECT pm.post_id FROM {$wpdb->postmeta} AS pm LEFT JOIN {$wpdb->posts} AS p ON (p.ID = pm.post_id AND p.post_type = 'shop_coupon') WHERE pm.meta_key = 'customer_email' AND pm.meta_value LIKE %s", '%' . $wpdb->esc_like( $email ) . '%' ) ); // WPCS: db call ok. wp_cache_set( 'wc_sc_get_coupon_ids_by_email_' . sanitize_key( $email ), $post_ids, 'woocommerce_smart_coupons' ); $this->maybe_add_cache_key( 'wc_sc_get_coupon_ids_by_email_' . sanitize_key( $email ) ); } if ( empty( $post_ids ) ) { return; } unset( $wp->query_vars['s'] ); $wp->query_vars['post__in'] = $post_ids; $wp->query_vars['email'] = $email; } } /** * Function to show label of the search result on coupon * * @param mixed $query Query. * @return mixed $query */ public function filter_coupons_using_meta_label( $query ) { global $pagenow, $typenow, $wp; if ( 'edit.php' !== $pagenow ) { return $query; } if ( 'shop_coupon' !== $typenow ) { return $query; } $s = get_query_var( 's' ); if ( ! empty( $s ) ) { return $query; } $email = get_query_var( 'email' ); if ( ! empty( $email ) ) { $post_type = get_post_type_object( $wp->query_vars['post_type'] ); /* translators: 1: Singular name for post type 2: Email */ return sprintf( __( '[%1$s restricted with email: %2$s]', 'woocommerce-smart-coupons' ), $post_type->labels->name, $email ); } return $query; } /** * WooCommerce Navigation Is Connected Page * * @param boolean $is_connected_page Is connected page. * @param string $current_page The current page. * @return boolean */ public function woocommerce_navigation_is_connected_page( $is_connected_page = false, $current_page = '' ) { $get_page = ( ! empty( $_GET['page'] ) ) ? wc_clean( wp_unslash( $_GET['page'] ) ) : ''; // phpcs:ignore if ( empty( $is_connected_page ) && 'wc-smart-coupons' === $get_page ) { return true; } return $is_connected_page; } /** * WooCommerce Navigation Is Connected Page * * @param boolean $breadcrumbs The breadcrumbs. * @param string $current_page The current page. * @return boolean */ public function woocommerce_navigation_breadcrumbs( $breadcrumbs = array(), $current_page = '' ) { global $store_credit_label; $get_page = ( ! empty( $_GET['page'] ) ) ? wc_clean( wp_unslash( $_GET['page'] ) ) : ''; // phpcs:ignore if ( 'wc-smart-coupons' === $get_page ) { $breadcrumbs = $this->get_default_breadcrumbs(); $get_tab = ( ! empty( $_GET['tab'] ) ) ? wc_clean( wp_unslash( $_GET['tab'] ) ) : ''; // phpcs:ignore switch ( $get_tab ) { case 'import-smart-coupons': $breadcrumbs[] = __( 'Import Coupons', 'woocommerce-smart-coupons' ); break; case 'send-smart-coupons': /* translators: Store Credit label */ $breadcrumbs[] = sprintf( __( 'Send %s', 'woocommerce-smart-coupons' ), ( ( ! empty( $store_credit_label['singular'] ) ) ? ucwords( $store_credit_label['singular'] ) : __( 'Store Credit', 'woocommerce-smart-coupons' ) ) ); break; default: $breadcrumbs[] = __( 'Bulk Generate', 'woocommerce-smart-coupons' ); break; } } return $breadcrumbs; } /** * Default breadcrums * * @return array */ public function get_default_breadcrumbs() { $breadcrumbs = array(); $breadcrumbs[] = array( 'admin.php?page=wc-admin', __( 'WooCommerce', 'woocommerce-smart-coupons' ), ); if ( $this->is_wc_gte_44() ) { // To make sure that the WooCommerce is 4.4 or greater. $breadcrumbs[] = array( 'admin.php?page=wc-admin&path=/marketing', __( 'Marketing', 'woocommerce-smart-coupons' ), ); } $breadcrumbs[] = array( 'edit.php?post_type=shop_coupon', __( 'Coupons', 'woocommerce-smart-coupons' ), ); return $breadcrumbs; } /** * Function to add a column to display original amount for store credit to coupons list * * @param array $columns The columns. * @return array */ public function add_original_amount_column( $columns = array() ) { if ( ! array_key_exists( 'wc_sc_original_amount', $columns ) ) { $columns['wc_sc_original_amount'] = __( 'Original amount', 'woocommerce-smart-coupons' ); } return $columns; } /** * Function to add value to the column to display original amount * * @param string $column The column id. * @param integer $post_id The post id. */ public function add_original_amount_column_value( $column = '', $post_id = 0 ) { if ( 'wc_sc_original_amount' === $column ) { $column_value = $this->get_post_meta( $post_id, $column, true ); if ( ! empty( $column_value ) ) { echo esc_html( $column_value ); } else { echo esc_html( '' ); } } } } } WC_SC_Admin_Pages::get_instance();