sections => fields. * @return array */ public static function fields( $fields ) { $fields = (array) $fields; if ( ! isset( $fields['side_cart']['sections'] ) || ! is_array( $fields['side_cart']['sections'] ) ) { return $fields; } $sections = $fields['side_cart']['sections']; $behaviour = array( 'side_cart_force_ajax' => array( 'type' => 'toggle', 'label' => __( 'Add to cart without reloading in product lists', 'aiolos-checkout-for-woocommerce' ), 'default' => 'yes', 'description' => __( 'Turns on WooCommerce\'s AJAX add to cart in shop and category pages while the side cart is on, and drops the "added to your cart" notice the side cart already shows.', 'aiolos-checkout-for-woocommerce' ), ), 'side_cart_shake' => array( 'type' => 'toggle', 'label' => __( 'Shake the cart button instead of opening the cart', 'aiolos-checkout-for-woocommerce' ), 'default' => 'no', 'description' => __( 'When a product is added, the floating button shakes and the side cart stays closed until it is clicked.', 'aiolos-checkout-for-woocommerce' ), ), 'side_cart_express' => array( 'type' => 'toggle', 'label' => __( 'Express payment buttons', 'aiolos-checkout-for-woocommerce' ), 'default' => 'yes', 'description' => __( 'Shows the buttons payment plugins add to WooCommerce\'s mini cart (PayPal, Apple Pay, Google Pay and others) under the Checkout button.', 'aiolos-checkout-for-woocommerce' ), ), 'side_cart_continue' => array( 'type' => 'toggle', 'label' => __( '"Continue shopping" button', 'aiolos-checkout-for-woocommerce' ), 'default' => 'no', 'description' => __( 'Under the Checkout button; closes the side cart.', 'aiolos-checkout-for-woocommerce' ), ), 'side_cart_empty_image' => array( 'type' => 'image', 'label' => __( 'Empty cart image', 'aiolos-checkout-for-woocommerce' ), 'default' => 0, 'description' => __( 'Shown when the cart is empty, instead of the bag icon.', 'aiolos-checkout-for-woocommerce' ), ), ); $button = array( 'label' => __( 'Floating cart button', 'aiolos-checkout-for-woocommerce' ), 'fields' => array( 'side_cart_button_icon' => array( 'type' => 'select', 'label' => __( 'Icon', 'aiolos-checkout-for-woocommerce' ), 'default' => 'bag', 'options' => array( 'bag' => __( 'Bag', 'aiolos-checkout-for-woocommerce' ), 'bag-solid' => __( 'Bag (filled)', 'aiolos-checkout-for-woocommerce' ), 'cart' => __( 'Cart', 'aiolos-checkout-for-woocommerce' ), 'basket' => __( 'Basket', 'aiolos-checkout-for-woocommerce' ), 'custom' => __( 'My own (SVG below)', 'aiolos-checkout-for-woocommerce' ), ), 'description' => __( 'Also used by the [aiolos_cart] shortcode and the "Aiolos cart button" block.', 'aiolos-checkout-for-woocommerce' ), ), 'side_cart_button_svg' => array( 'type' => 'json', 'label' => __( 'My own icon (SVG)', 'aiolos-checkout-for-woocommerce' ), 'default' => '', 'render' => array( self::class, 'render_svg_field' ), 'sanitize' => array( CartButton::class, 'sanitize_svg' ), 'description' => __( 'Paste the code of an SVG file (open it in a text editor). Shapes only: scripts, styles, links and images are removed. Use currentColor to follow the icon color.', 'aiolos-checkout-for-woocommerce' ), ), 'side_cart_button_color' => array( 'type' => 'color', 'label' => __( 'Icon color', 'aiolos-checkout-for-woocommerce' ), 'default' => '#111827', ), 'side_cart_button_bg' => array( 'type' => 'color', 'label' => __( 'Background', 'aiolos-checkout-for-woocommerce' ), 'default' => '#ffffff', ), 'side_cart_button_size' => array( 'type' => 'number', 'label' => __( 'Icon size (px)', 'aiolos-checkout-for-woocommerce' ), 'default' => 34, 'min' => 18, 'max' => 64, ), 'side_cart_button_x' => array( 'type' => 'number', 'label' => __( 'Distance from the side (px)', 'aiolos-checkout-for-woocommerce' ), 'default' => 20, 'min' => 0, 'max' => 200, 'description' => __( 'The side is chosen in "Floating cart button" above.', 'aiolos-checkout-for-woocommerce' ), ), 'side_cart_button_y' => array( 'type' => 'number', 'label' => __( 'Distance from the bottom (px)', 'aiolos-checkout-for-woocommerce' ), 'default' => 20, 'min' => 0, 'max' => 300, ), 'side_cart_button_devices' => array( 'type' => 'select', 'label' => __( 'Show on', 'aiolos-checkout-for-woocommerce' ), 'default' => 'all', 'options' => array( 'all' => __( 'All devices', 'aiolos-checkout-for-woocommerce' ), 'desktop' => __( 'Computers and tablets only', 'aiolos-checkout-for-woocommerce' ), 'mobile' => __( 'Phones only', 'aiolos-checkout-for-woocommerce' ), ), ), 'side_cart_button_empty' => array( 'type' => 'toggle', 'label' => __( 'Show while the cart is empty', 'aiolos-checkout-for-woocommerce' ), 'default' => 'no', 'description' => __( 'Off: the button appears once something is in the cart.', 'aiolos-checkout-for-woocommerce' ), ), ), ); if ( isset( $sections['behaviour']['fields'] ) && is_array( $sections['behaviour']['fields'] ) ) { $sections['behaviour']['fields'] = self::insert_after( $sections['behaviour']['fields'], 'side_cart_ajax_single', $behaviour ); } else { $sections['behaviour'] = array( 'label' => __( 'Behaviour', 'aiolos-checkout-for-woocommerce' ), 'fields' => $behaviour, ); } $sections = self::insert_after( $sections, 'behaviour', array( 'button' => $button ) ); // Free shipping bar: shipping classes that do not count, and a warning when the bar and // WooCommerce's own free shipping disagree. if ( isset( $sections['shipping_bar']['fields'] ) && is_array( $sections['shipping_bar']['fields'] ) ) { $sections['shipping_bar']['fields']['free_shipping_excluded_classes'] = array( 'type' => 'json', 'label' => __( 'Shipping classes that do not count', 'aiolos-checkout-for-woocommerce' ), 'default' => array(), 'render' => array( self::class, 'render_classes_field' ), 'sanitize' => array( self::class, 'sanitize_classes' ), 'description' => __( 'Products of these shipping classes (bulky items, for example) are left out of the amount the bar counts.', 'aiolos-checkout-for-woocommerce' ), ); // Only while the screen is drawn (not while the settings themselves are being read). $warning = did_action( 'current_screen' ) && self::on_side_cart_tab() ? Rewards::threshold_warning() : ''; if ( '' !== $warning ) { $sections['shipping_bar']['description'] = $warning; } } $fields['side_cart']['sections'] = $sections; return $fields; } /** * Whether this request shows the "Side cart" settings tab (the zone check runs only there). */ private static function on_side_cart_tab(): bool { // phpcs:disable WordPress.Security.NonceVerification.Recommended -- read-only screen check. return is_admin() && ! wp_doing_ajax() && isset( $_GET['page'], $_GET['tab'] ) && 'aiolos-checkout' === sanitize_key( wp_unslash( $_GET['page'] ) ) && 'side_cart' === sanitize_key( wp_unslash( $_GET['tab'] ) ); // phpcs:enable } /** * Checkboxes for the store's shipping classes. * * @param string $name Input name. * @param mixed $value Saved value. */ public static function render_classes_field( $name, $value ): void { $chosen = array_map( 'absint', is_array( $value ) ? $value : array() ); $classes = function_exists( 'WC' ) && WC()->shipping() ? WC()->shipping()->get_shipping_classes() : array(); ?>