session ) ) { return; } $get_session_cookie = WC()->session->get_session_cookie(); if ( empty( $get_session_cookie ) ) { WC()->session->set_customer_session_cookie( true ); } WC()->session->set( $name, $value ); } } if ( ! function_exists( 'beetan_get_wc_session' ) ) { /** * Get WooCommerce Session * * @param $name * * @return array|string */ function beetan_get_wc_session( $name ) { if ( ! did_action( 'woocommerce_init' ) ) { _doing_it_wrong( __FUNCTION__, esc_html__( 'This function should not be called before woocommerce_init.', 'beetan' ), '2.3' ); return ''; } if ( ! isset( WC()->session ) ) { return ''; } return WC()->session->get( $name ); } } if ( ! function_exists( 'beetan_delete_wc_session' ) ) { /** * Delete WooCommerce Session * * @param $name * * @return string|void */ function beetan_delete_wc_session( $name ) { if ( ! did_action( 'woocommerce_init' ) ) { _doing_it_wrong( __FUNCTION__, esc_html__( 'This function should not be called before woocommerce_init.', 'beetan' ), '2.3' ); return ''; } if ( ! isset( WC()->session ) ) { return ''; } WC()->session->set( $name, null ); } } if ( ! function_exists( 'beetan_wc_get_currencies' ) ) { /** * WooCommerce Get Currency list * * @return array */ function beetan_wc_get_currencies() { $currency_code_options = (array) get_woocommerce_currencies(); foreach ( $currency_code_options as $code => $name ) { // $currency_code_options[ $code ] = sprintf( '%s ( %s )', $name, get_woocommerce_currency_symbol( $code ) ); $currency_code_options[ $code ] = html_entity_decode( sprintf( '%s ( %s )', $name, get_woocommerce_currency_symbol( $code ) ) ); } return $currency_code_options; } } if ( ! function_exists( 'beetan_wc_get_currency_position' ) ) { /** * WooCommerce Get Currency icon position * * @return array */ function beetan_wc_get_currency_position() { $currency_symbol = html_entity_decode( get_woocommerce_currency_symbol() ); return array( 'left' => sprintf( esc_html__( 'Left (%s99.99)', 'beetan' ), $currency_symbol ), // phpcs:ignore WordPress.WP.I18n.MissingTranslatorsComment 'right' => sprintf( esc_html__( 'Right (99.99%s)', 'beetan' ), $currency_symbol ), // phpcs:ignore WordPress.WP.I18n.MissingTranslatorsComment 'left_space' => sprintf( esc_html__( 'Left with space (%s 99.99)', 'beetan' ), $currency_symbol ), // phpcs:ignore WordPress.WP.I18n.MissingTranslatorsComment 'right_space' => sprintf( esc_html__( 'Right with space (99.99 %s)', 'beetan' ), $currency_symbol ) // phpcs:ignore WordPress.WP.I18n.MissingTranslatorsComment ); } } if ( ! function_exists( 'beetan_single_ajax_add_to_cart' ) ) { /** * Single product ajax add to cart */ function beetan_single_ajax_add_to_cart() { check_ajax_referer( 'beetan_single_product_nonce', 'ajax_nonce' ); WC_Form_Handler::add_to_cart_action(); WC_AJAX::get_refreshed_fragments(); } } if ( ! function_exists( 'beetan_ajax_add_to_cart_add_fragments' ) ) { /** * Notice html to cart fragments * * @param $fragments * * @return mixed */ function beetan_ajax_add_to_cart_add_fragments( $fragments ) { $all_notices = WC()->session->get( 'wc_notices', array() ); $notice_types = apply_filters( 'woocommerce_notice_types', array( 'error', 'success', 'notice' ) ); ob_start(); foreach ( $notice_types as $notice_type ) { if ( wc_notice_count( $notice_type ) > 0 ) { wc_get_template( "notices/{$notice_type}.php", array( 'messages' => array_filter( $all_notices[ $notice_type ] ), 'notices' => array_filter( $all_notices[ $notice_type ] ), ) ); } } $fragments['notices_html'] = ob_get_clean(); wc_clear_notices(); return $fragments; } } if ( ! function_exists( 'beetan_product_quantity_button' ) ) { /** * Product quantity plus minus button */ function beetan_product_quantity_button() { echo '
'; } } if ( ! function_exists( 'beetan_product_sale_percentage' ) ) { /** * Product discount percentage */ function beetan_product_sale_percentage() { global $product; $percentages = array(); $product_type = $product->get_type(); $is_on_sale = $product->is_on_sale(); if ( ! $is_on_sale ) { return false; } if ( 'variable' == $product_type ) { $prices = $product->get_variation_prices(); foreach ( $prices['price'] as $key => $price ) { // Only on sale variations if ( $prices['regular_price'][ $key ] !== $price ) { $percentages[] = round( 100 - ( floatval( $prices['sale_price'][ $key ] ) / floatval( $prices['regular_price'][ $key ] ) * 100 ) ); } } // Keep the highest value $percentage = max( $percentages ) . '%'; } elseif ( 'grouped' == $product_type ) { $children_ids = $product->get_children(); foreach ( $children_ids as $child_id ) { $child_product = wc_get_product( $child_id ); $regular_price = (float) $child_product->get_regular_price(); $sale_price = (float) $child_product->get_sale_price(); if ( $sale_price != 0 || ! empty( $sale_price ) ) { $percentages[] = round( 100 - ( $sale_price / $regular_price * 100 ) ); } } // Keep the highest value $percentage = max( $percentages ) . '%'; } else { $regular_price = (float) $product->get_regular_price(); $sale_price = (float) $product->get_sale_price(); if ( $sale_price != 0 || ! empty( $sale_price ) ) { $percentage = round( 100 - ( $sale_price / $regular_price * 100 ) ) . '%'; } else { return false; } } return printf( '%s%s', absint( $percentage ), esc_html__( '% OFF', 'beetan' ) ); } } if ( ! function_exists( 'beetan_product_brand' ) ) { function beetan_product_brand() { $brand_obj = wp_get_object_terms( get_the_ID(), 'product_brand' ); if ( is_wp_error( $brand_obj ) ) { return; } if ( ! empty( $brand_obj ) ) { $brand_array = wp_list_pluck( $brand_obj, 'name' ); $brand_name = implode( ',', $brand_array ); echo '' . esc_html( $brand_name ) . ''; } } } if ( class_exists( 'Woo_Variation_Gallery' ) ) { /** * Additional Variation Image Gallery plugin compatible */ add_filter( 'woo_variation_gallery_default_width', function ( $width ) { $width = 48; return $width; } ); } if ( ! function_exists( 'beetan_shop_product_title' ) ) { /** * Shop product title */ function beetan_shop_product_title() { echo ''; woocommerce_template_loop_product_title(); echo ''; } } if ( ! function_exists( 'beetan_shop_product_img_overlay' ) ) { /** * Shop thumbnail overlay */ function beetan_shop_product_img_overlay() { echo ''; } } if ( ! function_exists( 'beetan_shop_item_view_details_button' ) ) { /** * Shop view details button */ function beetan_shop_item_view_details_button() { printf( '%s', esc_url( get_the_permalink() ), esc_html__( 'View Details', 'beetan' ) ); } } if ( ! function_exists( 'beetan_change_shop_pagination_arrow' ) ) { /** * Change shop page pagination arrow * * @param $args * * @return mixed */ function beetan_change_shop_pagination_arrow( $args ) { $args['prev_text'] = ''; $args['next_text'] = ''; return $args; } } if ( ! function_exists( 'beetan_button_proceed_to_checkout' ) ) { /** * Change cart page `Proceed to Checkout` button text */ function beetan_button_proceed_to_checkout() { $button_text = get_theme_mod( 'proceed_to_checkout_button_text' ); if ( ! empty( $button_text ) ) { printf( '%s', esc_url( wc_get_checkout_url() ), esc_html( $button_text ) ); } } } if ( ! function_exists( 'beetan_order_review_wrap_before' ) ) { /** * Checkout wrapper */ function beetan_order_review_wrap_before() { echo '