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; } if ( !empty(aio_get_option( 'opt-wc-show-price' )) ) { add_action( 'woocommerce_variable_add_to_cart', 'aio_update_price_with_variation_price' ); } function aio_update_price_with_variation_price() { global $product; $price = $product->get_price_html(); wc_enqueue_js( " $(document).on('found_variation', 'form.cart', function( event, variation ) { if(variation.price_html) $('p.price').html(variation.price_html); $('.woocommerce-variation-price').hide(); }); $(document).on('hide_variation', 'form.cart', function( event, variation ) { $('p.price').html('" . $price . "'); }); " ); } if ( !empty(aio_get_option( 'opt-enable-wc' )) ) { // Frontend Hooks add_filter( 'woocommerce_checkout_fields', 'aio_CustomDisplayWooCheckoutFields'); if(aio_get_option( 'opt-enable-vn-checkout' ) == 1){ add_filter('woocommerce_checkout_fields', 'woocommerce_reorder_vn_checkout_fields', 9999); include_once ( AIO_PUBLIC_PATH . 'section/wc-city-select/class-aio-provinces.php'); $Provinces = new AIO_Provinces(); include_once ( AIO_PUBLIC_PATH . 'section/wc-city-select/class-aio-cities.php'); new AIO_Cities(); } } // Direct Checkout Modes $direct_checkout_mode = aio_get_option('optDirectCheckoutMode', ''); if (empty($direct_checkout_mode) && !empty(aio_get_option('opt-direct-checkout'))) { $direct_checkout_mode = 'redirect'; // Legacy fallback } if ($direct_checkout_mode === 'redirect') { add_filter('woocommerce_add_to_cart_redirect', 'aio_direct_checkout_redirect'); } elseif ($direct_checkout_mode === 'lightbox') { add_action('wp_footer', 'aio_render_quick_buy_lightbox'); } function aio_render_quick_buy_lightbox() { if ( ! function_exists( 'is_woocommerce' ) ) return; ?>

×
0đ
get_status() == 'processing' || $order->get_status() == 'on-hold') { $order->update_status('completed'); } } // Custom Place Order Button Text if (!empty(aio_get_option('txtPlaceOrderText'))) { add_filter('woocommerce_order_button_text', 'aio_custom_place_order_text'); } function aio_custom_place_order_text($text) { return esc_html(aio_get_option('txtPlaceOrderText')); } // Sticky Add To Cart if (!empty(aio_get_option('optStickyAddToCart'))) { add_action('wp_footer', 'aio_render_sticky_add_to_cart'); } function aio_render_sticky_add_to_cart() { if ( ! function_exists( 'is_product' ) || ! is_product() ) return; global $product; if (!$product) return; ?>
get_image('thumbnail', array('class' => 'aio-sc-img')); ?>
get_name(); ?>
get_price_html(); ?>
is_in_stock()) { wp_send_json_error(esc_html__('Product is out of stock or does not exist.', 'aio')); } $order = wc_create_order(); $order->add_product($product, $qty); $address_data = array( 'first_name' => $name, 'phone' => $phone, 'address_1' => $address, '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')); $order->calculate_totals(); $order->update_status('processing', esc_html__('Order created via AIO Quick Buy.', 'aio'), true); wp_send_json_success(array( 'message' => esc_html__('Order placed successfully! We will contact you soon.', 'aio'), 'redirect' => $order->get_checkout_order_received_url() )); } function aio_CustomDisplayWooCheckoutFields($fields) { // Ignore admin, feed, robots or trackbacks if ( is_admin() || is_feed() || is_robots() || is_trackback() ) { return; } if(aio_get_option( 'opt-first-name' ) == 1){ unset($fields['billing']['billing_first_name']); unset($fields['shipping']['shipping_first_name']); } if(aio_get_option( 'opt-last-name' ) == 1){ unset($fields['billing']['billing_last_name']); unset($fields['shipping']['shipping_last_name']); } if(aio_get_option( 'opt-company' ) == 1){ unset($fields['billing']['billing_company']); unset($fields['shipping']['shipping_company']); } if(aio_get_option( 'opt-address-1' ) == 1){ unset($fields['billing']['billing_address_1']); unset($fields['shipping']['shipping_address_1']); } if(aio_get_option( 'opt-address-2' ) == 1){ unset($fields['billing']['billing_address_2']); unset($fields['shipping']['shipping_address_2']); } if(aio_get_option( 'opt-city' ) == 1){ unset($fields['billing']['billing_city']); unset($fields['shipping']['shipping_city']); } if(aio_get_option( 'opt-postcode' ) == 1){ unset($fields['billing']['billing_postcode']); unset($fields['shipping']['shipping_postcode']); } if(aio_get_option( 'opt-country' ) == 1){ unset($fields['billing']['billing_country']); unset($fields['shipping']['shipping_country']); } if(aio_get_option( 'opt-state' ) == 1){ unset($fields['billing']['billing_state']); unset($fields['shipping']['shipping_state']); } if(aio_get_option( 'opt-phone' ) == 1){ unset($fields['billing']['billing_phone']); } if(aio_get_option( 'opt-email' ) == 1){ unset($fields['billing']['billing_email']); } return $fields; } if ( ! function_exists( 'woocommerce_reorder_vn_checkout_fields' ) ) { function woocommerce_reorder_vn_checkout_fields( $fields ) { $i = 0; /* To reorder state field you need to add this array. */ $order = array( "billing_last_name", "billing_first_name", "billing_phone", "billing_email", "billing_address_1", "billing_state", "billing_city", ); foreach($order as $field) { $ordered_fields[ $field ] = $fields[ "billing" ][ $field ]; $ordered_fields[ $field ][ "priority" ] = ++$i; } $fields["billing"] = $ordered_fields; /* To change email and phone number you have to add only class no need to add priority. */ $fields['billing']['billing_country']['default'] = 'Việt Nam'; $fields['billing']['billing_country']['class'][0] = 'hidden'; $fields['billing']['billing_last_name']['class'][0] = 'form-row-first'; $fields['billing']['billing_first_name']['class'][0] = 'form-row-last'; $fields['billing']['billing_phone']['class'][0] = 'form-row-first'; $fields['billing']['billing_email']['class'][0] = 'form-row-last'; $fields['billing']['billing_address_1']['class'][0] = 'form-row-wide'; //$fields['billing']['billing_country']['class'][0] = 'form-row-last'; $fields['billing']['billing_state']['class'][0] = 'form-row-last'; $fields['billing']['billing_city']['class'][0] = 'form-row-first'; return $fields; } }