id = 'teams'; $this->label = __( 'Teams', 'sportspress' ); add_filter( 'sportspress_settings_tabs_array', array( $this, 'add_settings_page' ), 20 ); add_action( 'sportspress_settings_' . $this->id, array( $this, 'output' ) ); add_action( 'sportspress_settings_save_' . $this->id, array( $this, 'save' ) ); } /** * Get settings array * * @return array */ public function get_settings() { $tax_classes = array_filter( array_map( 'trim', explode( "\n", get_option( 'sportspress_tax_classes' ) ) ) ); $classes_options = array(); if ( $tax_classes ) foreach ( $tax_classes as $class ) $classes_options[ sanitize_title( $class ) ] = esc_html( $class ); return apply_filters('sportspress_event_settings', array( array( 'title' => __( 'Team Options', 'sportspress' ), 'type' => 'title','desc' => '', 'id' => 'tax_options' ), array( 'title' => __( 'Enable Teams', 'sportspress' ), 'desc' => __( 'Enable taxes and tax calculations', 'sportspress' ), 'id' => 'sportspress_calc_taxes', 'default' => 'no', 'type' => 'checkbox' ), array( 'title' => __( 'Prices Entered With Tax', 'sportspress' ), 'id' => 'sportspress_prices_include_tax', 'default' => 'no', 'type' => 'radio', 'options' => array( 'vs' => sprintf( '%s vs %s', __( 'Team', 'sportspress' ), __( 'Team', 'sportspress' ) ), 'v' => sprintf( '%s v %s', __( 'Team', 'sportspress' ), __( 'Team', 'sportspress' ) ), '—' => sprintf( '%s — %s', __( 'Team', 'sportspress' ), __( 'Team', 'sportspress' ) ), '/' => sprintf( '%s / %s', __( 'Team', 'sportspress' ), __( 'Team', 'sportspress' ) ) ), ), array( 'title' => __( 'Calculate Tax Based On:', 'sportspress' ), 'id' => 'sportspress_tax_based_on', 'desc_tip' => __( 'This option determines which address is used to calculate tax.', 'sportspress' ), 'default' => 'shipping', 'type' => 'select', 'options' => array( 'shipping' => __( 'Customer shipping address', 'sportspress' ), 'billing' => __( 'Customer billing address', 'sportspress' ), 'base' => __( 'Shop base address', 'sportspress' ) ), ), array( 'title' => __( 'Default Customer Address:', 'sportspress' ), 'id' => 'sportspress_default_customer_address', 'desc_tip' => __( 'This option determines the customers default address (before they input their own).', 'sportspress' ), 'default' => 'base', 'type' => 'select', 'options' => array( '' => __( 'No address', 'sportspress' ), 'base' => __( 'Shop base address', 'sportspress' ), ), ), array( 'title' => __( 'Shipping Tax Class:', 'sportspress' ), 'desc' => __( 'Optionally control which tax class shipping gets, or leave it so shipping tax is based on the cart items themselves.', 'sportspress' ), 'id' => 'sportspress_shipping_tax_class', 'css' => 'min-width:150px;', 'default' => 'title', 'type' => 'select', 'options' => array( '' => __( 'Shipping tax class based on cart items', 'sportspress' ), 'standard' => __( 'Standard', 'sportspress' ) ) + $classes_options, 'desc_tip' => true, ), array( 'title' => __( 'Rounding', 'sportspress' ), 'desc' => __( 'Round tax at subtotal level, instead of rounding per line', 'sportspress' ), 'id' => 'sportspress_tax_round_at_subtotal', 'default' => 'no', 'type' => 'checkbox', ), array( 'title' => __( 'Additional Tax Classes', 'sportspress' ), 'desc' => __( 'List additonal tax classes below (1 per line). This is in addition to the default Standard Rate. Tax classes can be assigned to products.', 'sportspress' ), 'id' => 'sportspress_tax_classes', 'css' => 'width:100%; height: 65px;', 'type' => 'textarea', 'default' => sprintf( __( 'Reduced Rate%sZero Rate', 'sportspress' ), PHP_EOL ) ), array( 'title' => __( 'Display prices in the shop:', 'sportspress' ), 'id' => 'sportspress_tax_display_shop', 'default' => 'excl', 'type' => 'select', 'options' => array( 'incl' => __( 'Including tax', 'sportspress' ), 'excl' => __( 'Excluding tax', 'sportspress' ), ) ), array( 'title' => __( 'Price display suffix:', 'sportspress' ), 'id' => 'sportspress_price_display_suffix', 'default' => '', 'type' => 'text', 'desc' => __( 'Define text to show after your product prices. This could be, for example, "inc. Vat" to explain your pricing. You can also have prices substituted here using one of the following: {price_including_tax}, {price_excluding_tax}.', 'sportspress' ), ), array( 'title' => __( 'Display prices during cart/checkout:', 'sportspress' ), 'id' => 'sportspress_tax_display_cart', 'default' => 'excl', 'type' => 'select', 'options' => array( 'incl' => __( 'Including tax', 'sportspress' ), 'excl' => __( 'Excluding tax', 'sportspress' ), ), 'autoload' => false ), array( 'title' => __( 'Display tax totals:', 'sportspress' ), 'id' => 'sportspress_tax_total_display', 'default' => 'itemized', 'type' => 'select', 'options' => array( 'single' => __( 'As a single total', 'sportspress' ), 'itemized' => __( 'Itemized', 'sportspress' ), ), 'autoload' => false ), array( 'type' => 'results' ), array( 'type' => 'sectionend', 'id' => 'event_options' ), )); // End event settings } /** * Output the settings */ public function output() { global $current_section; $tax_classes = array_filter( array_map( 'trim', explode( "\n", get_option('sportspress_tax_classes' ) ) ) ); if ( $current_section == 'standard' || in_array( $current_section, array_map( 'sanitize_title', $tax_classes ) ) ) { $this->output_tax_rates(); } else { $settings = $this->get_settings(); SP_Admin_Settings::output_fields( $settings ); } } /** * Save settings */ public function save() { global $current_section, $wpdb; if ( ! $current_section ) { $settings = $this->get_settings(); SP_Admin_Settings::save_fields( $settings ); } else { $this->save_tax_rates(); } $wpdb->query( "DELETE FROM `$wpdb->options` WHERE `option_name` LIKE ('_transient_sp_tax_rates_%') OR `option_name` LIKE ('_transient_timeout_sp_tax_rates_%')" ); } /** * Output tax rate tables */ public function output_tax_rates() { global $sportspress, $current_section, $wpdb; $page = ! empty( $_GET['p'] ) ? absint( $_GET['p'] ) : 1; $limit = 100; $tax_classes = array_filter( array_map( 'trim', explode( "\n", get_option('sportspress_tax_classes' ) ) ) ); $current_class = ''; foreach( $tax_classes as $class ) if ( sanitize_title( $class ) == $current_section ) $current_class = $class; ?>

See here for available alpha-2 country codes.', 'sportspress' ), 'http://en.wikipedia.org/wiki/ISO_3166-1#Current_codes' ); ?>

get_results( $wpdb->prepare( "SELECT * FROM {$wpdb->prefix}sportspress_tax_rates WHERE tax_rate_class = %s ORDER BY tax_rate_order LIMIT %d, %d " , sanitize_title( $current_class ), ( $page - 1 ) * $limit, $limit ) ); foreach ( $rates as $rate ) { ?>
   [?]  [?]  [?]  [?]  [?]  [?]  [?]  [?]  [?]
prefix}sportspress_tax_rate_locations WHERE location_type='postcode' AND tax_rate_id = %d ORDER BY location_code", $rate->tax_rate_id ) ); echo esc_attr( implode( '; ', $locations ) ); ?>" placeholder="*" data-name="tax_rate_postcode[tax_rate_id ?>]" /> prefix}sportspress_tax_rate_locations WHERE location_type='city' AND tax_rate_id = %d ORDER BY location_code", $rate->tax_rate_id ) ); echo esc_attr( implode( '; ', $locations ) ); ?>" placeholder="*" data-name="tax_rate_city[tax_rate_id ?>]" /> tax_rate_compound, '1' ); ?> /> tax_rate_shipping, '1' ); ?> />
$value ) { // new keys are inserted... if ( $key == 'new' ) { foreach ( $value as $new_key => $new_value ) { // Sanitize + format $country = strtoupper( sanitize_text_field( $tax_rate_country[ $key ][ $new_key ] ) ); $state = strtoupper( sanitize_text_field( $tax_rate_state[ $key ][ $new_key ] ) ); $postcode = sanitize_text_field( $tax_rate_postcode[ $key ][ $new_key ] ); $city = sanitize_text_field( $tax_rate_city[ $key ][ $new_key ] ); $rate = number_format( sanitize_text_field( $tax_rate[ $key ][ $new_key ] ), 4, '.', '' ); $name = sanitize_text_field( $tax_rate_name[ $key ][ $new_key ] ); $priority = absint( sanitize_text_field( $tax_rate_priority[ $key ][ $new_key ] ) ); $compound = isset( $tax_rate_compound[ $key ][ $new_key ] ) ? 1 : 0; $shipping = isset( $tax_rate_shipping[ $key ][ $new_key ] ) ? 1 : 0; if ( ! $name ) $name = __( 'Tax', 'sportspress' ); if ( $country == '*' ) $country = ''; if ( $state == '*' ) $state = ''; $wpdb->insert( $wpdb->prefix . "sportspress_tax_rates", array( 'tax_rate_country' => $country, 'tax_rate_state' => $state, 'tax_rate' => $rate, 'tax_rate_name' => $name, 'tax_rate_priority' => $priority, 'tax_rate_compound' => $compound, 'tax_rate_shipping' => $shipping, 'tax_rate_order' => $i, 'tax_rate_class' => sanitize_title( $current_class ) ) ); $tax_rate_id = $wpdb->insert_id; if ( ! empty( $postcode ) ) { $postcodes = explode( ';', $postcode ); $postcodes = array_map( 'strtoupper', array_map( 'sanitize_text_field', $postcodes ) ); $postcode_query = array(); foreach( $postcodes as $postcode ) if ( strstr( $postcode, '-' ) ) { $postcode_parts = explode( '-', $postcode ); if ( is_numeric( $postcode_parts[0] ) && is_numeric( $postcode_parts[1] ) && $postcode_parts[1] > $postcode_parts[0] ) { for ( $i = $postcode_parts[0]; $i <= $postcode_parts[1]; $i ++ ) { if ( ! $i ) continue; if ( strlen( $i ) < strlen( $postcode_parts[0] ) ) $i = str_pad( $i, strlen( $postcode_parts[0] ), "0", STR_PAD_LEFT ); $postcode_query[] = "( '" . esc_sql( $i ) . "', $tax_rate_id, 'postcode' )"; } } } else { if ( $postcode ) $postcode_query[] = "( '" . esc_sql( $postcode ) . "', $tax_rate_id, 'postcode' )"; } $wpdb->query( "INSERT INTO {$wpdb->prefix}sportspress_tax_rate_locations ( location_code, tax_rate_id, location_type ) VALUES " . implode( ',', $postcode_query ) ); } if ( ! empty( $city ) ) { $cities = explode( ';', $city ); $cities = array_map( 'strtoupper', array_map( 'sanitize_text_field', $cities ) ); foreach( $cities as $city ) { $wpdb->insert( $wpdb->prefix . "sportspress_tax_rate_locations", array( 'location_code' => $city, 'tax_rate_id' => $tax_rate_id, 'location_type' => 'city', ) ); } } $i++; } // ...whereas the others are updated } else { $tax_rate_id = absint( $key ); if ( $_POST['remove_tax_rate'][ $key ] == 1 ) { $wpdb->query( $wpdb->prepare( "DELETE FROM {$wpdb->prefix}sportspress_tax_rate_locations WHERE tax_rate_id = %d;", $tax_rate_id ) ); $wpdb->query( $wpdb->prepare( "DELETE FROM {$wpdb->prefix}sportspress_tax_rates WHERE tax_rate_id = %d;", $tax_rate_id ) ); continue; } // Sanitize + format $country = strtoupper( sanitize_text_field( $tax_rate_country[ $key ] ) ); $state = strtoupper( sanitize_text_field( $tax_rate_state[ $key ] ) ); $rate = number_format( (double) sanitize_text_field( $tax_rate[ $key ] ), 4, '.', '' ); $name = sanitize_text_field( $tax_rate_name[ $key ] ); $priority = absint( sanitize_text_field( $tax_rate_priority[ $key ] ) ); $compound = isset( $tax_rate_compound[ $key ] ) ? 1 : 0; $shipping = isset( $tax_rate_shipping[ $key ] ) ? 1 : 0; if ( ! $name ) $name = __( 'Tax', 'sportspress' ); if ( $country == '*' ) $country = ''; if ( $state == '*' ) $state = ''; $wpdb->update( $wpdb->prefix . "sportspress_tax_rates", array( 'tax_rate_country' => $country, 'tax_rate_state' => $state, 'tax_rate' => $rate, 'tax_rate_name' => $name, 'tax_rate_priority' => $priority, 'tax_rate_compound' => $compound, 'tax_rate_shipping' => $shipping, 'tax_rate_order' => $i, 'tax_rate_class' => sanitize_title( $current_class ) ), array( 'tax_rate_id' => $tax_rate_id ) ); if ( isset( $tax_rate_postcode[ $key ] ) ) { // Delete old $wpdb->query( $wpdb->prepare( "DELETE FROM {$wpdb->prefix}sportspress_tax_rate_locations WHERE tax_rate_id = %d AND location_type = 'postcode';", $tax_rate_id ) ); // Add changed $postcode = sanitize_text_field( $tax_rate_postcode[ $key ] ); $postcodes = explode( ';', $postcode ); $postcodes = array_map( 'strtoupper', array_map( 'sanitize_text_field', $postcodes ) ); $postcode_query = array(); foreach( $postcodes as $postcode ) if ( strstr( $postcode, '-' ) ) { $postcode_parts = explode( '-', $postcode ); if ( is_numeric( $postcode_parts[0] ) && is_numeric( $postcode_parts[1] ) && $postcode_parts[1] > $postcode_parts[0] ) { for ( $i = $postcode_parts[0]; $i <= $postcode_parts[1]; $i ++ ) { if ( ! $i ) continue; if ( strlen( $i ) < strlen( $postcode_parts[0] ) ) $i = str_pad( $i, strlen( $postcode_parts[0] ), "0", STR_PAD_LEFT ); $postcode_query[] = "( '" . esc_sql( $i ) . "', $tax_rate_id, 'postcode' )"; } } } else { if ( $postcode ) $postcode_query[] = "( '" . esc_sql( $postcode ) . "', $tax_rate_id, 'postcode' )"; } $wpdb->query( "INSERT INTO {$wpdb->prefix}sportspress_tax_rate_locations ( location_code, tax_rate_id, location_type ) VALUES " . implode( ',', $postcode_query ) ); } if ( isset( $tax_rate_city[ $key ] ) ) { // Delete old $wpdb->query( $wpdb->prepare( "DELETE FROM {$wpdb->prefix}sportspress_tax_rate_locations WHERE tax_rate_id = %d AND location_type = 'city';", $tax_rate_id ) ); // Add changed $city = sanitize_text_field( $tax_rate_city[ $key ] ); $cities = explode( ';', $city ); $cities = array_map( 'strtoupper', array_map( 'sanitize_text_field', $cities ) ); foreach( $cities as $city ) { if ( $city ) { $wpdb->insert( $wpdb->prefix . "sportspress_tax_rate_locations", array( 'location_code' => $city, 'tax_rate_id' => $tax_rate_id, 'location_type' => 'city', ) ); } } } $i++; } } } /** * Output results settings. * * @access public * @return void */ public function results_setting() { $main_result = get_option( 'sportspress_main_result', 0 ); $args = array( 'post_type' => 'sp_result', 'numberposts' => -1, 'posts_per_page' => -1, 'orderby' => 'menu_order', 'order' => 'ASC' ); $data = get_posts( $args ); ?> >
>
post_name ); ?>> post_name; ?>for / post_name; ?>against