$this ) ); $max_coupon_to_show = absint( $max_coupon_to_show ); $coupons = array(); if ( $max_coupon_to_show > 0 ) { $coupons = $this->sc_get_available_coupons_list( array(), $args ); } if ( empty( $coupons ) ) { do_action( 'wc_sc_no_available_coupons', array( 'available_coupons_heading' => $available_coupons_heading, 'page' => $page, ) ); return false; } if ( ! wp_style_is( 'smart-coupon' ) ) { wp_enqueue_style( 'smart-coupon' ); } $design = get_option( 'wc_sc_setting_coupon_design', 'basic' ); $background_color = get_option( 'wc_sc_setting_coupon_background_color', '#39cccc' ); $foreground_color = get_option( 'wc_sc_setting_coupon_foreground_color', '#30050b' ); $third_color = get_option( 'wc_sc_setting_coupon_third_color', '#39cccc' ); $show_coupon_description = get_option( 'smart_coupons_show_coupon_description', 'no' ); $valid_designs = $this->get_valid_coupon_designs(); if ( ! in_array( $design, $valid_designs, true ) ) { $design = 'basic'; } ?>
show_available_coupons_before_checkout_form(); die(); } /** * Function to show available coupons before checkout form */ public function show_available_coupons_before_checkout_form() { $smart_coupon_cart_page_text = get_option( 'smart_coupon_cart_page_text' ); $smart_coupon_cart_page_text = ( ! empty( $smart_coupon_cart_page_text ) ) ? $smart_coupon_cart_page_text : __( 'Available Coupons (click on a coupon to use it)', 'woocommerce-smart-coupons' ); $this->show_available_coupons( $smart_coupon_cart_page_text, 'checkout' ); } /** * Check if store credit is valid based on amount * * @param boolean $is_valid Validity. * @param array $args Additional arguments. * @return boolean Validity. */ public function show_as_valid( $is_valid = false, $args = array() ) { $coupon = ( ! empty( $args['coupon_obj'] ) ) ? $args['coupon_obj'] : false; if ( empty( $coupon ) ) { return $is_valid; } if ( $this->is_wc_gte_30() ) { $discount_type = ( is_object( $coupon ) && is_callable( array( $coupon, 'get_discount_type' ) ) ) ? $coupon->get_discount_type() : ''; } else { $discount_type = ( ! empty( $coupon->discount_type ) ) ? $coupon->discount_type : ''; } $coupon_amount = $this->get_amount( $coupon, true ); if ( true === $is_valid && 'smart_coupon' === $discount_type && empty( $coupon_amount ) ) { return false; } return $is_valid; } /** * Hooks for handling display of coupons on My Account page */ public function myaccount_display_coupons() { $is_show_on_my_account = get_option( 'woocommerce_smart_coupon_show_my_account', 'yes' ); if ( 'yes' !== $is_show_on_my_account ) { return; } if ( $this->is_wc_gte_26() ) { add_filter( 'woocommerce_get_query_vars', array( $this, 'sc_add_query_vars' ) ); // Change the My Account page title. add_filter( 'the_title', array( $this, 'sc_endpoint_title' ) ); // Inserting our new tab/page into the My Account page. add_filter( 'woocommerce_account_menu_items', array( $this, 'sc_new_menu_items' ) ); add_action( 'woocommerce_account_' . self::$endpoint . '_endpoint', array( $this, 'sc_endpoint_content' ) ); } else { add_action( 'woocommerce_before_my_account', array( $this, 'show_smart_coupon_balance' ) ); add_action( 'woocommerce_before_my_account', array( $this, 'generated_coupon_details_before_my_account' ) ); } } /** * Function to show gift certificates that are attached with the product */ public function show_attached_gift_certificates() { global $post; if ( empty( $post->ID ) ) { return; } $is_show_associated_coupons = get_option( 'smart_coupons_is_show_associated_coupons', 'no' ); if ( 'yes' !== $is_show_associated_coupons ) { return; } add_action( 'wp_footer', array( $this, 'attached_coupons_styles_and_scripts' ) ); ?> ID ); ?> get_coupon_titles( array( 'product_object' => $_product ) ); if ( $this->is_wc_gte_30() ) { $product_type = ( is_object( $_product ) && is_callable( array( $_product, 'get_type' ) ) ) ? $_product->get_type() : ''; } else { $product_type = ( ! empty( $_product->product_type ) ) ? $_product->product_type : ''; } $sell_sc_at_less_price = get_option( 'smart_coupons_sell_store_credit_at_less_price', 'no' ); $generated_credit_includes_tax = $this->is_generated_store_credit_includes_tax(); if ( 'yes' === $sell_sc_at_less_price ) { if ( is_a( $_product, 'WC_Product_Variable' ) ) { $price = ( is_object( $_product ) && is_callable( array( $_product, 'get_variation_regular_price' ) ) ) ? $_product->get_variation_regular_price( 'max' ) : 0; } else { $price = ( is_object( $_product ) && is_callable( array( $_product, 'get_regular_price' ) ) ) ? $_product->get_regular_price() : 0; } } else { if ( is_a( $_product, 'WC_Product_Variable' ) ) { $price = ( is_object( $_product ) && is_callable( array( $_product, 'get_variation_price' ) ) ) ? $_product->get_variation_price( 'max' ) : 0; } else { $price = ( is_object( $_product ) && is_callable( array( $_product, 'get_price' ) ) ) ? $_product->get_price() : 0; } } if ( $coupon_titles && count( $coupon_titles ) > 0 && ! empty( $price ) ) { $all_discount_types = wc_get_coupon_types(); $smart_coupons_product_page_text = get_option( 'smart_coupon_product_page_text' ); $smart_coupons_product_page_text = ( ! empty( $smart_coupons_product_page_text ) ) ? $smart_coupons_product_page_text : __( 'You will get following coupon(s) when you buy this item:', 'woocommerce-smart-coupons' ); $list_started = true; ob_start(); foreach ( $coupon_titles as $coupon_title ) { $coupon = new WC_Coupon( $coupon_title ); $is_callable_coupon_get_meta = $this->is_callable( $coupon, 'get_meta' ); if ( $this->is_wc_gte_30() ) { if ( ! is_object( $coupon ) || ! is_callable( array( $coupon, 'get_id' ) ) ) { continue; } $coupon_id = $coupon->get_id(); if ( empty( $coupon_id ) ) { continue; } $discount_type = $coupon->get_discount_type(); $is_free_shipping = ( $coupon->get_free_shipping() ) ? 'yes' : 'no'; $product_ids = $coupon->get_product_ids(); $excluded_product_ids = $coupon->get_excluded_product_ids(); $product_categories = $coupon->get_product_categories(); $excluded_product_categories = $coupon->get_excluded_product_categories(); } else { $coupon_id = ( ! empty( $coupon->id ) ) ? $coupon->id : 0; $discount_type = ( ! empty( $coupon->discount_type ) ) ? $coupon->discount_type : ''; $is_free_shipping = ( ! empty( $coupon->free_shipping ) ) ? $coupon->free_shipping : ''; $product_ids = ( ! empty( $coupon->product_ids ) ) ? $coupon->product_ids : array(); $excluded_product_ids = ( ! empty( $coupon->exclude_product_ids ) ) ? $coupon->exclude_product_ids : array(); $product_categories = ( ! empty( $coupon->product_categories ) ) ? $coupon->product_categories : array(); $excluded_product_categories = ( ! empty( $coupon->exclude_product_categories ) ) ? $coupon->exclude_product_categories : array(); } $coupon_amount = $this->get_amount( $coupon, true ); $is_pick_price_of_product = ( true === $is_callable_coupon_get_meta ) ? $coupon->get_meta( 'is_pick_price_of_product' ) : get_post_meta( $coupon_id, 'is_pick_price_of_product', true ); if ( $list_started && ! empty( $discount_type ) ) { echo '' . esc_html( wp_unslash( $smart_coupons_product_page_text ) ) . ''; echo '
$this, 'all_coupon_data' => $coupon_block_data, ) ), $allowed_html ); ?>
' . esc_html_x( 'Order actions', 'Generated coupons metabox - Order edit admin page', 'woocommerce-smart-coupons' ) . '', '' . esc_html_x( 'Order actions', 'Generated coupons metabox - Order edit admin page', 'woocommerce-smart-coupons' ) . '', '' . esc_html_x( 'arrow', 'Generated coupons metabox - Order edit admin page', 'woocommerce-smart-coupons' ) . '' ); ?>
' . esc_html__( 'List of coupons & their details which you have received from the store. Click on the coupon to see the details.', 'woocommerce-smart-coupons' ) . '
'; } echo $coupon_details_html_content; // phpcs:ignore echo ''; } return; } return $generated_coupon_data; } /** * HTML code to display generated coupon's data in box layout * * @param array $generated_coupon_data Associative array containing generated coupon's details. */ public function get_generated_coupon_data_box( $generated_coupon_data = array() ) { if ( empty( $generated_coupon_data ) ) { return; } $design = get_option( 'wc_sc_setting_coupon_design', 'basic' ); $background_color = get_option( 'wc_sc_setting_coupon_background_color', '#39cccc' ); $foreground_color = get_option( 'wc_sc_setting_coupon_foreground_color', '#30050b' ); $third_color = get_option( 'wc_sc_setting_coupon_third_color', '#39cccc' ); $show_coupon_description = get_option( 'smart_coupons_show_coupon_description', 'no' ); $valid_designs = $this->get_valid_coupon_designs(); if ( ! in_array( $design, $valid_designs, true ) ) { $design = 'basic'; } $current_filter = current_filter(); if ( 'woocommerce_email_after_order_table' === $current_filter ) { $design = 'email-coupon'; } $email = $this->get_current_user_email(); $js = " var switchMoreLess = function() { var total = jQuery('details').length; var open = jQuery('details[open]').length; if ( open == total ) { jQuery('a#more_less').text('" . __( 'Less details', 'woocommerce-smart-coupons' ) . "'); } else { jQuery('a#more_less').text('" . __( 'More details', 'woocommerce-smart-coupons' ) . "'); } }; switchMoreLess(); jQuery('a#more_less').on('click', function(){ var current = jQuery('details').attr('open'); if ( current == '' || current == undefined ) { jQuery('details').attr('open', 'open'); jQuery('a#more_less').text('" . __( 'Less details', 'woocommerce-smart-coupons' ) . "'); } else { jQuery('details').removeAttr('open'); jQuery('a#more_less').text('" . __( 'More details', 'woocommerce-smart-coupons' ) . "'); } }); jQuery('summary.generated_coupon_summary').on('mouseup', function(){ setTimeout( switchMoreLess, 10 ); }); jQuery('span.expand_collapse').show(); var generated_coupon_element = jQuery('#all_generated_coupon'); var generated_coupon_container_height = generated_coupon_element.height(); if ( generated_coupon_container_height > 400 ) { generated_coupon_element.css('height', '400px'); generated_coupon_element.css('overflow-y', 'scroll'); } else { generated_coupon_element.css('height', ''); generated_coupon_element.css('overflow-y', ''); } jQuery('#all_generated_coupon').on('click', '.coupon-container', function(){ setTimeout(function(){ var current_element = jQuery(this).find('details'); var is_open = current_element.attr('open'); if ( is_open == '' || is_open == undefined ) { current_element.attr('open', 'open'); } else { current_element.removeAttr('open'); } }, 1); }); "; wc_enqueue_js( $js ); ?>:
:
:
| ' . esc_html( $coupon_data['code'] ) . ' | '; echo '' . wc_price( $coupon_data['amount'] ) . ' | '; // phpcs:ignore echo '' . esc_html( $coupon_data['email'] ) . ' | '; echo '' . esc_html( $coupon_data['message'] ) . ' | '; echo '' . esc_html( $from ) . ' | '; echo '
' . $storewide_offer_coupon_code . '' ) ) {
if ( ! empty( $this->sc_coupon_exists( $storewide_offer_coupon_code ) ) ) {
$coupon = new WC_Coupon( $storewide_offer_coupon_code );
$is_percent = $this->is_percent_coupon( array( 'coupon_object' => $coupon ) );
if ( false === $is_percent ) {
$coupon_amount = ( is_object( $coupon ) && is_callable( array( $coupon, 'get_amount' ) ) ) ? $coupon->get_amount( 'edit' ) : 0;
$search = get_woocommerce_currency_symbol( $base_currency ) . $coupon_amount;
$replace = get_woocommerce_currency_symbol( $current_currency ) . $this->convert_price( $coupon_amount, $current_currency, $base_currency );
$displayed_notice = str_replace( $search, $replace, $displayed_notice );
}
}
}
}
return $displayed_notice;
}
}
}
WC_SC_Display_Coupons::get_instance();