From 9a98be6a153ac8c2839aee6600e7feb217201ecf Mon Sep 17 00:00:00 2001 From: Mike Jolley Date: Tue, 24 Sep 2013 12:24:26 +0100 Subject: [PATCH] WOOCOMMERCE_DELIMITER constant. Closes #3476. --- .../meta-boxes/class-wc-meta-box-product-data.php | 8 ++++---- .../post-types/meta-boxes/views/html-variation-admin.php | 2 +- includes/class-wc-form-handler.php | 2 +- includes/class-wc-product-variable.php | 4 ++-- .../shipping/flat-rate/class-wc-shipping-flat-rate.php | 6 +++--- readme.txt | 1 + templates/single-product/product-attributes.php | 2 +- woocommerce-ajax.php | 6 +++--- woocommerce.php | 2 ++ 9 files changed, 18 insertions(+), 15 deletions(-) diff --git a/includes/admin/post-types/meta-boxes/class-wc-meta-box-product-data.php b/includes/admin/post-types/meta-boxes/class-wc-meta-box-product-data.php index 61a2ea706b0..a892a34fc45 100644 --- a/includes/admin/post-types/meta-boxes/class-wc-meta-box-product-data.php +++ b/includes/admin/post-types/meta-boxes/class-wc-meta-box-product-data.php @@ -482,7 +482,7 @@ class WC_Meta_Box_Product_Data { $values = array(); foreach ( $post_terms as $term ) $values[] = $term->name; - echo esc_attr( implode( ' | ', $values ) ); + echo esc_attr( implode( ' ' . WOOCOMMERCE_DELIMITER . ' ', $values ) ); } ?>" placeholder="" /> @@ -907,7 +907,7 @@ class WC_Meta_Box_Product_Data { } else { - $options = array_map( 'trim', explode( '|', $attribute['value'] ) ); + $options = array_map( 'trim', explode( WOOCOMMERCE_DELIMITER, $attribute['value'] ) ); foreach ( $options as $option ) echo ''; @@ -1034,7 +1034,7 @@ class WC_Meta_Box_Product_Data { // Text based attributes - Posted values are term names - don't change to slugs } else { - $values = array_map( 'stripslashes', array_map( 'strip_tags', explode( '|', $attribute_values[ $i ] ) ) ); + $values = array_map( 'stripslashes', array_map( 'strip_tags', explode( WOOCOMMERCE_DELIMITER, $attribute_values[ $i ] ) ) ); } // Remove empty items in the array @@ -1063,7 +1063,7 @@ class WC_Meta_Box_Product_Data { } elseif ( isset( $attribute_values[ $i ] ) ) { // Text based, separate by pipe - $values = implode( ' | ', array_map( 'woocommerce_clean', explode( '|', $attribute_values[ $i ] ) ) ); + $values = implode( ' ' . WOOCOMMERCE_DELIMITER . ' ', array_map( 'woocommerce_clean', explode( WOOCOMMERCE_DELIMITER, $attribute_values[ $i ] ) ) ); // Custom attribute - Add attribute to array and set the values $attributes[ sanitize_title( $attribute_names[ $i ] ) ] = array( diff --git a/includes/admin/post-types/meta-boxes/views/html-variation-admin.php b/includes/admin/post-types/meta-boxes/views/html-variation-admin.php index 6d81d8d0d1d..5aa90b29f36 100644 --- a/includes/admin/post-types/meta-boxes/views/html-variation-admin.php +++ b/includes/admin/post-types/meta-boxes/views/html-variation-admin.php @@ -30,7 +30,7 @@ if ( ! defined( 'ABSPATH' ) ) exit; // Exit if accessed directly } else { - $options = array_map( 'trim', explode( '|', $attribute['value'] ) ); + $options = array_map( 'trim', explode( WOOCOMMERCE_DELIMITER, $attribute['value'] ) ); foreach ( $options as $option ) { echo ''; diff --git a/includes/class-wc-form-handler.php b/includes/class-wc-form-handler.php index b874e9f333c..0f0e6176b87 100644 --- a/includes/class-wc-form-handler.php +++ b/includes/class-wc-form-handler.php @@ -506,7 +506,7 @@ class WC_Form_Handler { $variations[ $taxonomy ] = $value; else { // For custom attributes, get the name from the slug - $options = array_map( 'trim', explode( '|', $attribute['value'] ) ); + $options = array_map( 'trim', explode( WOOCOMMERCE_DELIMITER, $attribute['value'] ) ); foreach ( $options as $option ) { if ( sanitize_title( $option ) == $value ) { $value = $option; diff --git a/includes/class-wc-product-variable.php b/includes/class-wc-product-variable.php index 8af6052efc7..200faba3350 100644 --- a/includes/class-wc-product-variable.php +++ b/includes/class-wc-product-variable.php @@ -299,7 +299,7 @@ class WC_Product_Variable extends WC_Product { foreach ( $post_terms as $term ) $values[] = $term->slug; } else { - $values = array_map( 'trim', explode( '|', $attribute['value'] ) ); + $values = array_map( 'trim', explode( WOOCOMMERCE_DELIMITER, $attribute['value'] ) ); } $values = array_unique( $values ); @@ -307,7 +307,7 @@ class WC_Product_Variable extends WC_Product { // Order custom attributes (non taxonomy) as defined } elseif ( ! $attribute['is_taxonomy'] ) { - $option_names = array_map( 'trim', explode( '|', $attribute['value'] ) ); + $option_names = array_map( 'trim', explode( WOOCOMMERCE_DELIMITER, $attribute['value'] ) ); $option_slugs = $values; $values = array(); diff --git a/includes/shipping/flat-rate/class-wc-shipping-flat-rate.php b/includes/shipping/flat-rate/class-wc-shipping-flat-rate.php index 37984387442..4d87ffaf08c 100644 --- a/includes/shipping/flat-rate/class-wc-shipping-flat-rate.php +++ b/includes/shipping/flat-rate/class-wc-shipping-flat-rate.php @@ -246,7 +246,7 @@ class WC_Shipping_Flat_Rate extends WC_Shipping_Method { // Loop options foreach ( $this->options as $option ) { - $this_option = array_map( 'trim', explode( '|', $option ) ); + $this_option = array_map( 'trim', explode( WOOCOMMERCE_DELIMITER, $option ) ); if ( sizeof( $this_option ) !== 3 ) continue; @@ -275,7 +275,7 @@ class WC_Shipping_Flat_Rate extends WC_Shipping_Method { switch ( $this_type ) { case 'class' : $this_cost = $this_cost * sizeof( $this->find_shipping_classes( $package ) ); - + // Factor $this_cost by the percentage if provided. if ( $this_cost_percents ) { foreach ( $this->find_shipping_classes( $package ) as $shipping_class => $items ){ @@ -292,7 +292,7 @@ class WC_Shipping_Flat_Rate extends WC_Shipping_Method { break; case 'item' : $this_cost = $this_cost * $total_quantity; - + // Factor $this_cost by the percentage if provided. if ( $this_cost_percents ) { foreach ( $package['contents'] as $item_id => $values ) { diff --git a/readme.txt b/readme.txt index 2a989ff2102..9c4aba23fe0 100644 --- a/readme.txt +++ b/readme.txt @@ -183,6 +183,7 @@ Yes you can! Join in on our [GitHub repository](http://github.com/woothemes/wooc * Feature - Handling for password protected products. * Feature - Schema markup selector for downloadables. * Feature - woocommerce_get_featured_product_ids function. +* Feature - WOOCOMMERCE_DELIMITER to customise the pipes for attributes * Tweak - Added pagination to tax rate screens. * Tweak - Added filter to check the 'Create account' checkbox on checkout by default. * Tweak - Update CPT parameters for 'product_variation' and 'shop_coupon' to be no longer public. diff --git a/templates/single-product/product-attributes.php b/templates/single-product/product-attributes.php index da78ca6e11c..5f9538c18cb 100644 --- a/templates/single-product/product-attributes.php +++ b/templates/single-product/product-attributes.php @@ -59,7 +59,7 @@ if ( empty( $attributes ) && ( ! $product->enable_dimensions_display() || ( ! $p } else { // Convert pipes to commas and display values - $values = array_map( 'trim', explode( '|', $attribute['value'] ) ); + $values = array_map( 'trim', explode( WOOCOMMERCE_DELIMITER, $attribute['value'] ) ); echo apply_filters( 'woocommerce_attribute', wpautop( wptexturize( implode( ', ', $values ) ) ), $attribute, $values ); } diff --git a/woocommerce-ajax.php b/woocommerce-ajax.php index c1fd67ea501..b255f973815 100644 --- a/woocommerce-ajax.php +++ b/woocommerce-ajax.php @@ -454,7 +454,7 @@ function woocommerce_save_attributes() { // Text based attributes - Posted values are term names - don't change to slugs } else { - $values = array_map( 'stripslashes', array_map( 'strip_tags', explode( '|', $attribute_values[ $i ] ) ) ); + $values = array_map( 'stripslashes', array_map( 'strip_tags', explode( WOOCOMMERCE_DELIMITER, $attribute_values[ $i ] ) ) ); } // Remove empty items in the array @@ -483,7 +483,7 @@ function woocommerce_save_attributes() { } elseif ( isset( $attribute_values[ $i ] ) ) { // Text based, separate by pipe - $values = implode( ' | ', array_map( 'woocommerce_clean', array_map( 'stripslashes', explode( '|', $attribute_values[ $i ] ) ) ) ); + $values = implode( ' ' . WOOCOMMERCE_DELIMITER . ' ', array_map( 'woocommerce_clean', array_map( 'stripslashes', explode( WOOCOMMERCE_DELIMITER, $attribute_values[ $i ] ) ) ) ); // Custom attribute - Add attribute to array and set the values $attributes[ sanitize_title( $attribute_names[ $i ] ) ] = array( @@ -635,7 +635,7 @@ function woocommerce_link_all_variations() { $options[] = $term->slug; } } else { - $options = explode( '|', $attribute['value'] ); + $options = explode( WOOCOMMERCE_DELIMITER, $attribute['value'] ); } $options = array_map( 'sanitize_title', array_map( 'trim', $options ) ); diff --git a/woocommerce.php b/woocommerce.php index 7c104525589..0495c47b277 100644 --- a/woocommerce.php +++ b/woocommerce.php @@ -91,6 +91,8 @@ final class WooCommerce { define( 'WOOCOMMERCE_PLUGIN_FILE', __FILE__ ); define( 'WOOCOMMERCE_VERSION', $this->version ); define( 'WOOCOMMERCE_TEMPLATE_PATH', $this->template_path() ); + if ( ! defined( 'WOOCOMMERCE_DELIMITER' ) ) + define( 'WOOCOMMERCE_DELIMITER', '|' ); // Include required files $this->includes();