array( // Translators: %s is the weight unit set in WooCommerce settings. 'description' => sprintf( __( 'Total Weight (%s)', 'advanced-shipping-rules-for-woocommerce' ), get_option( 'woocommerce_weight_unit' ) ), 'operators' => array( 'greater_than' => __( 'Greater than', 'advanced-shipping-rules-for-woocommerce' ), 'greater_than_or_equal' => __( 'Greater than or equal to', 'advanced-shipping-rules-for-woocommerce' ), 'less_than' => __( 'Less than', 'advanced-shipping-rules-for-woocommerce' ), 'less_than_or_equal' => __( 'Less than or equal to', 'advanced-shipping-rules-for-woocommerce' ), 'equal' => __( 'Equal to', 'advanced-shipping-rules-for-woocommerce' ), ), 'placeholder' => __( 'Enter weight', 'advanced-shipping-rules-for-woocommerce' ), 'input_type' => 'number', 'step' => 'any', ), 'products_number' => array( 'description' => __( 'Products Number', 'advanced-shipping-rules-for-woocommerce' ), 'operators' => array( 'greater_than' => __( 'Greater than', 'advanced-shipping-rules-for-woocommerce' ), 'greater_than_or_equal' => __( 'Greater than or equal to', 'advanced-shipping-rules-for-woocommerce' ), 'less_than' => __( 'Less than', 'advanced-shipping-rules-for-woocommerce' ), 'less_than_or_equal' => __( 'Less than or equal to', 'advanced-shipping-rules-for-woocommerce' ), 'equal' => __( 'Equal to', 'advanced-shipping-rules-for-woocommerce' ), ), 'placeholder' => __( 'Enter number of products', 'advanced-shipping-rules-for-woocommerce' ), 'input_type' => 'number', 'step' => '1', ), 'cart_total' => array( 'description' => __( 'Cart Total', 'advanced-shipping-rules-for-woocommerce' ), 'operators' => array( 'greater_than' => __( 'Greater than', 'advanced-shipping-rules-for-woocommerce' ), 'greater_than_or_equal' => __( 'Greater than or equal to', 'advanced-shipping-rules-for-woocommerce' ), 'less_than' => __( 'Less than', 'advanced-shipping-rules-for-woocommerce' ), 'less_than_or_equal' => __( 'Less than or equal to', 'advanced-shipping-rules-for-woocommerce' ), 'equal' => __( 'Equal to', 'advanced-shipping-rules-for-woocommerce' ), ), 'placeholder' => __( 'Enter cart total', 'advanced-shipping-rules-for-woocommerce' ), 'input_type' => 'number', 'step' => 'any', ), ) ); return $condition_types; } /** * Generates the HTML output for a shipping condition. * * @param string $condition_id The ID of the condition. Default is '%%CONDITION_ID_PLACEHOLDER%%'. * @param string $group_id The ID of the group. Default is '%%GROUP_ID_PLACEHOLDER%%'. * @return string The generated HTML for the shipping condition. */ public static function generate_html_shipping_condition( $condition_id = '%%CONDITION_ID_PLACEHOLDER%%', $group_id = '%%GROUP_ID_PLACEHOLDER%%' ): string { // Sanitize input IDs $condition_id = sanitize_text_field( $condition_id ); $group_id = sanitize_text_field( $group_id ); // Retrieve and sanitize condition values $condition = array( 'type' => sanitize_text_field( get_post_meta( $condition_id, '_condition_type', true ) ?: '' ), 'operator' => sanitize_text_field( get_post_meta( $condition_id, '_operator', true ) ?: '' ), ); // Get valid condition types $condition_types = self::get_condition_types(); // Validate condition type $valid_condition_types = array_keys( $condition_types ); if ( ! in_array( $condition['type'], $valid_condition_types, true ) && $condition_id !== '%%CONDITION_ID_PLACEHOLDER%%' ) { return ''; } // Get input type and step for selected condition type $input_type = $condition_types[ $condition['type'] ]['input_type'] ?? 'number'; $step = $condition_types[ $condition['type'] ]['step'] ?? 'any'; // Conditionally sanitize value based on input type $raw_value = (string) ( get_post_meta( $condition_id, '_value', true ) ?? '' ); $condition['value'] = ( $input_type === 'number' ) ? ( $raw_value !== '' ? floatval( $raw_value ) : '' ) : sanitize_text_field( $raw_value ); $available_operators = $condition_types[ $condition['type'] ]['operators'] ?? array(); $placeholder_for_value_field = $condition_types[ $condition['type'] ]['placeholder'] ?? __( 'Enter value', 'advanced-shipping-rules-for-woocommerce' ); ob_start(); ?>
ID ) : '%%GROUP_ID_PLACEHOLDER%%'; // Group cost (stored on the group post, not on individual conditions) $raw_group_cost = $group ? get_post_meta( $group_id, '_group_cost', true ) : ''; $group_cost_display = $raw_group_cost !== '' ? number_format( (float) $raw_group_cost, 2, '.', '' ) : ''; // Translators: %s is the currency symbol set in WooCommerce settings. $group_cost_placeholder = sprintf( __( 'Cost (%s)', 'advanced-shipping-rules-for-woocommerce' ), esc_html( get_woocommerce_currency_symbol() ) ); ?>
array( 'class' => array() ), 'select' => array( 'name' => array(), 'class' => array(), ), 'option' => array( 'value' => array(), 'selected' => array(), 'disabled' => array(), ), 'input' => array( 'type' => array(), 'name' => array(), 'class' => array(), 'value' => array(), 'min' => array(), 'step' => array(), 'placeholder' => array(), ), 'button' => array( 'type' => array(), 'class' => array(), 'disabled' => array(), ), '!--' => array(), // Allows HTML comments ); if ( is_array( $conditions ) && ! empty( $conditions ) ) { foreach ( $conditions as $condition_id ) { echo wp_kses( self::generate_html_shipping_condition( sanitize_text_field( $condition_id ), $group_id ), $allowed_html ); } } ?>
' . esc_html__( 'or', 'advanced-shipping-rules-for-woocommerce' ) . ''; } } }