is_type( 'variable' ) ) { $prices = $product->get_variation_prices( true ); $min_price = current( $prices['price'] ); if ( 0 == $min_price ) { $max_price = end( $prices['price'] ); $min_reg_price = current( $prices['regular_price'] ); $max_reg_price = end( $prices['regular_price'] ); if ( $min_price !== $max_price ) { $price = wc_format_price_range( $cfp_html, $max_price ); $price .= $product->get_price_suffix(); } elseif ( $product->is_on_sale() && $min_reg_price === $max_reg_price ) { $price = wc_format_sale_price( wc_price( $max_reg_price ), $cfp_html ); $price .= $product->get_price_suffix(); } else { $price = $cfp_html; } } } elseif ( '' === $product->get_price() || 0 == $product->get_price() ) { $price = '' . $cfp_html . ''; } return $price; } // Frontend Checkout Fields Customizer $custom_fields_json = aio_get_option( 'optWcCheckoutFields' ); $has_custom_fields = ! empty( $custom_fields_json ) && '[]' !== $custom_fields_json; if ( $has_custom_fields ) { add_filter( 'woocommerce_checkout_fields', 'aio_tools_CustomDisplayWooCheckoutFields', 99999 ); add_filter( 'woocommerce_enable_order_notes_field', 'aio_tools_disable_order_notes_heading', 9999 ); function aio_tools_disable_order_notes_heading( $enable ) { $custom_fields_json = aio_get_option( 'optWcCheckoutFields' ); if ( ! empty( $custom_fields_json ) ) { $custom_fields = json_decode( $custom_fields_json, true ); if ( is_array( $custom_fields ) ) { foreach ( $custom_fields as $cf ) { if ( isset( $cf['id'] ) && 'order_comments' === $cf['id'] ) { if ( ! isset( $cf['visible'] ) || ! $cf['visible'] ) { return false; } } } } } return $enable; } } if ( 1 == aio_get_option( 'optWcMergeNames' ) ) { add_filter( 'woocommerce_checkout_fields', 'aio_tools_merge_first_last_name', 100000 ); } function aio_tools_merge_first_last_name( $fields ) { if ( isset( $fields['billing']['billing_first_name'] ) ) { $fields['billing']['billing_first_name']['label'] = __( 'Full Name', 'aio-tools' ); $fields['billing']['billing_first_name']['placeholder'] = __( 'Enter your full name', 'aio-tools' ); $fields['billing']['billing_first_name']['class'] = [ 'form-row-wide' ]; } if ( isset( $fields['billing']['billing_last_name'] ) ) { unset( $fields['billing']['billing_last_name'] ); } if ( isset( $fields['shipping']['shipping_first_name'] ) ) { $fields['shipping']['shipping_first_name']['label'] = __( 'Full Name', 'aio-tools' ); $fields['shipping']['shipping_first_name']['placeholder'] = __( 'Enter your full name', 'aio-tools' ); $fields['shipping']['shipping_first_name']['class'] = [ 'form-row-wide' ]; } if ( isset( $fields['shipping']['shipping_last_name'] ) ) { unset( $fields['shipping']['shipping_last_name'] ); } return $fields; } // Direct Checkout Modes if ( ! empty( aio_get_option( 'opt-woo-direct-checkout' ) ) || ! empty( aio_get_option( 'opt-direct-checkout' ) ) ) { $direct_checkout_mode = aio_get_option( 'optDirectCheckoutMode', '' ); if ( empty( $direct_checkout_mode ) ) { $direct_checkout_mode = 'redirect'; } if ( 'redirect' === $direct_checkout_mode ) { add_filter( 'woocommerce_add_to_cart_redirect', 'aio_tools_direct_checkout_redirect' ); } elseif ( 'lightbox' === $direct_checkout_mode ) { add_action( 'wp_footer', 'aio_tools_render_quick_buy_lightbox' ); add_action( 'wp_ajax_aio_get_quick_buy_nonce', 'aio_tools_get_quick_buy_nonce_ajax' ); add_action( 'wp_ajax_nopriv_aio_get_quick_buy_nonce', 'aio_tools_get_quick_buy_nonce_ajax' ); add_action( 'wp_ajax_aio_quick_buy_process', 'aio_tools_quick_buy_process' ); add_action( 'wp_ajax_nopriv_aio_quick_buy_process', 'aio_tools_quick_buy_process' ); } } function aio_tools_get_quick_buy_nonce_ajax() { nocache_headers(); wp_send_json_success( [ 'nonce' => wp_create_nonce( 'aio-quick-buy' ) ] ); } function aio_tools_render_quick_buy_lightbox() { if ( ! function_exists( 'is_woocommerce' ) ) { return; } $prefill_name = ''; $prefill_phone = ''; $prefill_addr = ''; if ( is_user_logged_in() ) { $uid = get_current_user_id(); $first = get_user_meta( $uid, 'billing_first_name', true ); $last = get_user_meta( $uid, 'billing_last_name', true ); $prefill_name = trim( $first . ' ' . $last ); if ( '' === $prefill_name ) { $u = wp_get_current_user(); $prefill_name = $u ? $u->display_name : ''; } $prefill_phone = (string) get_user_meta( $uid, 'billing_phone', true ); $prefill_addr = (string) get_user_meta( $uid, 'billing_address_1', true ); } ?> get_status() ) { $order->update_status( 'completed', __( 'Auto-completed by AIO Tools.', 'aio-tools' ) ); } } // Custom Place Order Button Text if ( ! empty( aio_get_option( 'txtPlaceOrderText' ) ) ) { add_filter( 'woocommerce_order_button_text', 'aio_tools_custom_place_order_text' ); } function aio_tools_custom_place_order_text( $text ) { return esc_html( aio_get_option( 'txtPlaceOrderText' ) ); } // Sticky Add To Cart if ( ! empty( aio_get_option( 'opt-woo-sticky-cart' ) ) ) { add_action( 'wp_footer', 'aio_tools_render_sticky_add_to_cart' ); } function aio_tools_render_sticky_add_to_cart() { if ( ! function_exists( 'is_product' ) || ! is_product() ) { return; } global $product; if ( ! $product ) { return; } ?>
get_image( 'thumbnail', [ 'class' => 'aio-sc-img' ] ) ); ?>
get_name() ); ?>
get_price_html() ); ?>
= 5 ) { wp_send_json_error( esc_html__( 'You are ordering too fast. Please try again after 5 minutes.', 'aio-tools' ) ); } $product_id = isset( $_POST['product_id'] ) ? absint( $_POST['product_id'] ) : 0; $variation_id = isset( $_POST['variation_id'] ) ? absint( $_POST['variation_id'] ) : 0; $qty = isset( $_POST['qty'] ) ? max( 1, absint( $_POST['qty'] ) ) : 1; $name = isset( $_POST['name'] ) ? sanitize_text_field( wp_unslash( $_POST['name'] ) ) : ''; $phone = isset( $_POST['phone'] ) ? sanitize_text_field( wp_unslash( $_POST['phone'] ) ) : ''; $address = isset( $_POST['address'] ) ? sanitize_text_field( wp_unslash( $_POST['address'] ) ) : ''; $posted_attrs = []; if ( isset( $_POST['variation_attrs'] ) && is_array( $_POST['variation_attrs'] ) ) { // phpcs:ignore WordPress.Security.ValidatedSanitizedInput.InputNotSanitized foreach ( wp_unslash( $_POST['variation_attrs'] ) as $attr_k => $attr_v ) { $clean_k = sanitize_key( (string) $attr_k ); if ( 0 === strpos( $clean_k, 'attribute_' ) ) { $posted_attrs[ $clean_k ] = sanitize_text_field( (string) $attr_v ); } } } if ( ! $product_id || '' === $name || '' === $phone ) { wp_send_json_error( esc_html__( 'Please fill in all required fields (Name, Phone).', 'aio-tools' ) ); } $product = wc_get_product( $product_id ); if ( ! $product ) { wp_send_json_error( esc_html__( 'Product is out of stock or does not exist.', 'aio-tools' ) ); } $target_product = $product; if ( $product->is_type( 'variable' ) ) { if ( $variation_id <= 0 ) { wp_send_json_error( esc_html__( 'Please select product options before ordering.', 'aio-tools' ) ); } $variation = wc_get_product( $variation_id ); if ( ! $variation || ! $variation->is_type( 'variation' ) || (int) $variation->get_parent_id() !== (int) $product_id ) { wp_send_json_error( esc_html__( 'Invalid product variation selected.', 'aio-tools' ) ); } $target_product = $variation; } if ( ! $target_product->is_purchasable() || ! $target_product->is_in_stock() ) { wp_send_json_error( esc_html__( 'Product is out of stock or cannot be purchased.', 'aio-tools' ) ); } if ( $target_product->managing_stock() && ! $target_product->backorders_allowed() && ! $target_product->has_enough_stock( $qty ) ) { wp_send_json_error( sprintf( /* translators: %d: available stock quantity */ esc_html__( 'Sorry, only %d item(s) remain in stock.', 'aio-tools' ), (int) $target_product->get_stock_quantity() ) ); } set_transient( $rate_key, $requests + 1, 5 * MINUTE_IN_SECONDS ); $order = wc_create_order(); if ( is_wp_error( $order ) || ! $order ) { wp_send_json_error( esc_html__( 'Could not create order. Please try again.', 'aio-tools' ) ); } if ( is_user_logged_in() ) { $order->set_customer_id( get_current_user_id() ); } $item_args = ! empty( $posted_attrs ) ? [ 'variation' => $posted_attrs ] : []; $order->add_product( $target_product, $qty, $item_args ); $base_country = ( function_exists( 'WC' ) && WC()->countries ) ? WC()->countries->get_base_country() : 'VN'; $address_data = [ 'first_name' => $name, 'phone' => $phone, 'address_1' => $address, 'country' => $base_country ? $base_country : 'VN', ]; $order->set_address( $address_data, 'billing' ); $order->set_address( $address_data, 'shipping' ); $order->set_payment_method( 'cod' ); $order->set_payment_method_title( esc_html__( 'Cash on Delivery (COD)', 'aio-tools' ) ); $order->calculate_totals(); $order->update_status( 'processing', esc_html__( 'Order created via AIO Quick Buy.', 'aio-tools' ), true ); wp_send_json_success( [ 'message' => esc_html__( 'Order placed successfully! We will contact you soon.', 'aio-tools' ), 'redirect' => $order->get_checkout_order_received_url(), ] ); } function aio_tools_CustomDisplayWooCheckoutFields( $fields ) { if ( is_admin() && ! defined( 'DOING_AJAX' ) ) { return $fields; } $custom_fields_json = aio_get_option( 'optWcCheckoutFields' ); if ( ! empty( $custom_fields_json ) ) { $custom_fields = json_decode( $custom_fields_json, true ); if ( is_array( $custom_fields ) ) { $ordered_billing_fields = []; $priority = 10; foreach ( $custom_fields as $cf ) { $id = isset( $cf['id'] ) ? $cf['id'] : ''; if ( empty( $id ) ) { continue; } $group = ( 'order_comments' === $id ) ? 'order' : 'billing'; if ( ! isset( $cf['visible'] ) || ! $cf['visible'] ) { unset( $fields[ $group ][ $id ] ); continue; } if ( ! isset( $fields[ $group ][ $id ] ) ) { $fields[ $group ][ $id ] = [ 'type' => 'text', 'class' => [ 'form-row-wide' ], 'clear' => true, ]; } if ( isset( $cf['label'] ) ) { $fields[ $group ][ $id ]['label'] = sanitize_text_field( $cf['label'] ); } if ( isset( $cf['placeholder'] ) ) { $fields[ $group ][ $id ]['placeholder'] = sanitize_text_field( $cf['placeholder'] ); } if ( isset( $cf['required'] ) ) { $fields[ $group ][ $id ]['required'] = ! empty( $cf['required'] ); } if ( isset( $cf['width'] ) ) { $classes = isset( $fields[ $group ][ $id ]['class'] ) && is_array( $fields[ $group ][ $id ]['class'] ) ? $fields[ $group ][ $id ]['class'] : []; $classes = array_diff( $classes, [ 'form-row-wide', 'form-row-first', 'form-row-last' ] ); if ( 'half-left' === $cf['width'] ) { $classes[] = 'form-row-first'; } elseif ( 'half-right' === $cf['width'] ) { $classes[] = 'form-row-last'; } else { $classes[] = 'form-row-wide'; } $fields[ $group ][ $id ]['class'] = $classes; } $fields[ $group ][ $id ]['priority'] = $priority; $priority += 10; if ( 'billing' === $group ) { $ordered_billing_fields[ $id ] = $fields['billing'][ $id ]; } } if ( ! empty( $ordered_billing_fields ) ) { foreach ( $fields['billing'] as $k => $v ) { if ( ! isset( $ordered_billing_fields[ $k ] ) ) { $ordered_billing_fields[ $k ] = $v; } } $fields['billing'] = $ordered_billing_fields; } return $fields; } } // Legacy fallback if ( 1 == aio_get_option( 'opt-first-name' ) ) { unset( $fields['billing']['billing_first_name'], $fields['shipping']['billing_first_name'] ); } if ( 1 == aio_get_option( 'opt-last-name' ) ) { unset( $fields['billing']['billing_last_name'], $fields['shipping']['billing_last_name'] ); } if ( 1 == aio_get_option( 'opt-company' ) ) { unset( $fields['billing']['billing_company'], $fields['shipping']['shipping_company'] ); } if ( 1 == aio_get_option( 'opt-address-1' ) ) { unset( $fields['billing']['billing_address_1'], $fields['shipping']['billing_address_1'] ); } if ( 1 == aio_get_option( 'opt-address-2' ) ) { unset( $fields['billing']['billing_address_2'], $fields['shipping']['billing_address_2'] ); } if ( 1 == aio_get_option( 'opt-city' ) ) { unset( $fields['billing']['billing_city'], $fields['shipping']['billing_city'] ); } if ( 1 == aio_get_option( 'opt-postcode' ) ) { unset( $fields['billing']['billing_postcode'], $fields['shipping']['billing_postcode'] ); } if ( 1 == aio_get_option( 'opt-country' ) ) { unset( $fields['billing']['billing_country'], $fields['shipping']['billing_country'] ); } if ( 1 == aio_get_option( 'opt-state' ) ) { unset( $fields['billing']['billing_state'], $fields['shipping']['billing_state'] ); } if ( 1 == aio_get_option( 'opt-phone' ) ) { unset( $fields['billing']['billing_phone'] ); } if ( 1 == aio_get_option( 'opt-email' ) ) { unset( $fields['billing']['billing_email'] ); } return $fields; } add_action( 'woocommerce_admin_order_data_after_billing_address', 'aio_tools_display_custom_checkout_fields_in_admin', 10, 1 ); function aio_tools_display_custom_checkout_fields_in_admin( $order ) { $custom_fields_json = aio_get_option( 'optWcCheckoutFields' ); if ( empty( $custom_fields_json ) ) { return; } $custom_fields = json_decode( $custom_fields_json, true ); if ( ! is_array( $custom_fields ) ) { return; } foreach ( $custom_fields as $cf ) { $id = isset( $cf['id'] ) ? $cf['id'] : ''; $is_custom = isset( $cf['is_custom'] ) ? $cf['is_custom'] : false; if ( $is_custom && ! empty( $id ) ) { $value = $order->get_meta( '_' . $id ); if ( ! empty( $value ) ) { echo '

' . esc_html( $cf['label'] ) . ': ' . esc_html( $value ) . '

'; } } } } add_action( 'woocommerce_checkout_create_order', 'aio_tools_save_custom_checkout_fields_to_order', 10, 2 ); function aio_tools_save_custom_checkout_fields_to_order( $order, $data ) { $custom_fields_json = aio_get_option( 'optWcCheckoutFields' ); if ( empty( $custom_fields_json ) ) { return; } $custom_fields = json_decode( $custom_fields_json, true ); if ( ! is_array( $custom_fields ) ) { return; } foreach ( $custom_fields as $cf ) { $id = isset( $cf['id'] ) ? $cf['id'] : ''; $is_custom = isset( $cf['is_custom'] ) ? $cf['is_custom'] : false; // phpcs:ignore WordPress.Security.NonceVerification.Missing if ( $is_custom && ! empty( $id ) && isset( $_POST[ $id ] ) ) { // phpcs:ignore WordPress.Security.NonceVerification.Missing $order->update_meta_data( '_' . $id, sanitize_text_field( wp_unslash( $_POST[ $id ] ) ) ); } } } /* ========================================================================== WCP-1. ASSET UNLOADER ========================================================================== */ if ( ! empty( aio_get_option( 'optEnableWcUnloader' ) ) ) { add_action( 'wp_enqueue_scripts', 'aio_tools_wc_asset_unloader', 99 ); } function aio_tools_wc_asset_unloader() { if ( function_exists( 'is_woocommerce' ) ) { if ( ! is_woocommerce() && ! is_cart() && ! is_checkout() && ! is_account_page() ) { wp_dequeue_style( 'woocommerce-layout' ); wp_dequeue_style( 'woocommerce-smallscreen' ); wp_dequeue_style( 'woocommerce-general' ); wp_dequeue_style( 'wc-blocks-vendors-style' ); wp_dequeue_style( 'wc-blocks-style' ); wp_dequeue_script( 'wc-add-to-cart' ); wp_dequeue_script( 'woocommerce' ); if ( empty( aio_get_option( 'optWcSideCart' ) ) ) { wp_dequeue_script( 'wc-cart-fragments' ); } } } } /* ========================================================================== WCP-2. SOCIAL PROOF SALES POPUP (Real Recent Orders OR Virtual Mode) ========================================================================== */ if ( ! empty( aio_get_option( 'optEnableWcFakeSales' ) ) ) { add_action( 'wp_footer', 'aio_tools_render_fake_sales_popup' ); add_action( 'woocommerce_new_order', function () { delete_transient( 'aio_sales_popup_data_real' ); } ); } function aio_tools_render_fake_sales_popup() { if ( ! function_exists( 'wc_get_products' ) ) { return; } if ( function_exists( 'is_checkout' ) && is_checkout() ) { return; } $source = aio_get_option( 'optWcSalesSource', 'virtual' ); if ( 'real' === $source && function_exists( 'wc_get_orders' ) ) { $sales_data = get_transient( 'aio_sales_popup_data_real' ); if ( false === $sales_data ) { $sales_data = []; $orders = wc_get_orders( [ 'limit' => 15, 'status' => [ 'wc-processing', 'wc-completed' ], 'orderby' => 'date', 'order' => 'DESC', ] ); foreach ( $orders as $ord ) { $items = $ord->get_items(); if ( empty( $items ) ) { continue; } $first_item = reset( $items ); $prod = is_callable( [ $first_item, 'get_product' ] ) ? $first_item->get_product() : null; if ( ! $prod ) { continue; } $cust_name = trim( $ord->get_billing_first_name() ); $cust_city = trim( $ord->get_billing_city() ?: $ord->get_billing_state() ); $date_obj = $ord->get_date_created(); $time_label = $date_obj ? sprintf( /* translators: %s: human-readable time difference (e.g. "12 mins") */ __( '%s ago', 'aio-tools' ), human_time_diff( $date_obj->getTimestamp(), time() ) ) : __( 'Recently', 'aio-tools' ); $sales_data[] = [ 'headline' => $cust_city ? sprintf( /* translators: 1: customer first name, 2: city name */ __( '%1$s in %2$s purchased', 'aio-tools' ), $cust_name ?: __( 'A customer', 'aio-tools' ), $cust_city ) : sprintf( /* translators: %s: customer first name */ __( '%s purchased', 'aio-tools' ), $cust_name ?: __( 'A customer', 'aio-tools' ) ), 'product' => $prod->get_name(), 'url' => $prod->get_permalink(), 'image' => wp_get_attachment_image_url( $prod->get_image_id(), 'thumbnail' ), 'time' => $time_label, ]; } set_transient( 'aio_sales_popup_data_real', $sales_data, 30 * MINUTE_IN_SECONDS ); } } else { $sales_data = get_transient( 'aio_fake_sales_products' ); if ( false === $sales_data ) { $products = wc_get_products( [ 'status' => 'publish', 'limit' => 30, 'orderby' => 'date', 'order' => 'DESC', ] ); if ( empty( $products ) ) { return; } $raw_names = trim( (string) aio_get_option( 'optFakeSalesNames', '' ) ); $names = $raw_names ? array_values( array_filter( array_map( 'trim', preg_split( '/[\r\n,]+/', $raw_names ) ) ) ) : [ 'Nguyễn Văn Tuấn', 'Trần Thủy Tiên', 'Lê Hải Đăng', 'Phạm Minh Duy', 'Hoàng Thanh Tùng' ]; $raw_cities = trim( (string) aio_get_option( 'optFakeSalesCities', '' ) ); $cities = $raw_cities ? array_values( array_filter( array_map( 'trim', preg_split( '/[\r\n,]+/', $raw_cities ) ) ) ) : [ 'Hà Nội', 'TP.HCM', 'Đà Nẵng', 'Hải Phòng', 'Cần Thơ' ]; $sales_data = []; foreach ( $products as $product ) { $mins = wp_rand( 1, 55 ); $picked_name = $names[ array_rand( $names ) ]; $picked_city = $cities[ array_rand( $cities ) ]; $sales_data[] = [ 'headline' => sprintf( /* translators: 1: customer name, 2: city name */ __( '%1$s in %2$s purchased', 'aio-tools' ), $picked_name, $picked_city ), 'product' => $product->get_name(), 'url' => $product->get_permalink(), 'image' => wp_get_attachment_image_url( $product->get_image_id(), 'thumbnail' ), 'time' => sprintf( /* translators: %d: minutes ago */ __( '%d mins ago', 'aio-tools' ), $mins ), ]; } set_transient( 'aio_fake_sales_products', $sales_data, 2 * HOUR_IN_SECONDS ); } } if ( empty( $sales_data ) ) { return; } if ( count( $sales_data ) > 10 ) { $random_keys = (array) array_rand( $sales_data, 10 ); $filtered_data = array_intersect_key( $sales_data, array_flip( $random_keys ) ); $sales_data = array_values( $filtered_data ); } ?>
×

query_vars['order-received'] ) ? absint( $wp->query_vars['order-received'] ) : 0; $order = $order_id ? wc_get_order( $order_id ) : false; // Never redirect failed payments away from the retry payment screen if ( $order && $order->has_status( 'failed' ) ) { return; } // Ensure Auto-Complete Orders still runs if both features are enabled if ( $order && ! empty( aio_get_option( 'opt-woo-auto-complete' ) ) && 'processing' === $order->get_status() ) { $order->update_status( 'completed', __( 'Auto-completed by AIO Tools.', 'aio-tools' ) ); } $url = trim( (string) aio_get_option( 'optWcThankYouUrl', '' ) ); if ( '' === $url ) { return; } if ( 0 === strpos( $url, '/' ) ) { $url = home_url( $url ); } if ( $order_id ) { $url = add_query_arg( 'order_id', $order_id, $url ); } // phpcs:ignore WordPress.Security.SafeRedirect.wp_redirect_wp_redirect wp_redirect( esc_url_raw( $url ) ); exit; } /* ========================================================================== WCP-4. EMPTY CART REDIRECT ========================================================================== */ if ( ! empty( aio_get_option( 'optWcEmptyCartRedirect' ) ) ) { add_action( 'template_redirect', 'aio_tools_empty_cart_redirect' ); } function aio_tools_empty_cart_redirect() { if ( function_exists( 'is_cart' ) && function_exists( 'WC' ) && is_cart() && WC()->cart && WC()->cart->is_empty() ) { wp_safe_redirect( wc_get_page_permalink( 'shop' ) ); exit; } } /* ========================================================================== WCP-5. TRUST BADGES ========================================================================== */ if ( ! empty( aio_get_option( 'optWcTrustBadges' ) ) ) { add_action( 'woocommerce_after_add_to_cart_button', 'aio_tools_render_trust_badges' ); } function aio_tools_render_trust_badges() { ?>
is_in_stock() ) { return; } $stock = $product->get_stock_quantity(); if ( ! $stock || $stock > 10 ) { $stock = wp_rand( 2, 7 ); } $percentage = max( 10, min( 100, ( $stock / 20 ) * 100 ) ); ?>
0 ) { return $manual; } if ( ! class_exists( 'WC_Shipping_Zones' ) ) { return 0.0; } $zones = WC_Shipping_Zones::get_zones(); $zones[] = [ 'shipping_methods' => ( new WC_Shipping_Zone( 0 ) )->get_shipping_methods( true ) ]; foreach ( $zones as $zone ) { if ( empty( $zone['shipping_methods'] ) || ! is_array( $zone['shipping_methods'] ) ) { continue; } foreach ( $zone['shipping_methods'] as $method ) { if ( isset( $method->id, $method->enabled ) && 'free_shipping' === $method->id && 'yes' === $method->enabled ) { $min = (float) $method->get_option( 'min_amount', 0 ); if ( $min > 0 ) { return $min; } } } } return 0.0; } function aio_tools_get_free_shipping_bar_html() { if ( empty( aio_get_option( 'optWcFreeShippingBar' ) ) || ! function_exists( 'WC' ) || ! WC()->cart ) { return ''; } $goal = aio_tools_get_free_shipping_goal(); if ( $goal <= 0 ) { return ''; } $subtotal = (float) WC()->cart->get_displayed_subtotal(); $pct = min( 100, max( 0, ( $subtotal / $goal ) * 100 ) ); $remain = max( 0, $goal - $subtotal ); ob_start(); ?>
0 ) : ?>
%s more to unlock FREE Shipping!', 'aio-tools' ) ), wp_kses_post( wc_price( $remain ) ) ); ?>
✓
cart ? WC()->cart->get_cart_contents_count() : 0; $fragments['.aio-cart-count'] = '' . esc_html( $count ) . ''; $fragments['.aio-sc-shipping-bar'] = aio_tools_get_free_shipping_bar_html(); return $fragments; } function aio_tools_render_side_cart() { if ( ! function_exists( 'is_woocommerce' ) || ! function_exists( 'WC' ) ) { return; } if ( is_cart() || is_checkout() ) { return; } $count = WC()->cart ? WC()->cart->get_cart_contents_count() : 0; ?>

×