Merge pull request #18262 from woocommerce/fix/18100
Format prices while exporting products
This commit is contained in:
commit
c4e5556368
|
@ -16,7 +16,7 @@ if ( ! defined( 'ABSPATH' ) ) {
|
||||||
* Include dependencies.
|
* Include dependencies.
|
||||||
*/
|
*/
|
||||||
if ( ! class_exists( 'WC_CSV_Batch_Exporter', false ) ) {
|
if ( ! class_exists( 'WC_CSV_Batch_Exporter', false ) ) {
|
||||||
include_once( WC_ABSPATH . 'includes/export/abstract-wc-csv-batch-exporter.php' );
|
include_once WC_ABSPATH . 'includes/export/abstract-wc-csv-batch-exporter.php';
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -98,9 +98,13 @@ class WC_Product_CSV_Exporter extends WC_CSV_Batch_Exporter {
|
||||||
'stock' => __( 'Stock', 'woocommerce' ),
|
'stock' => __( 'Stock', 'woocommerce' ),
|
||||||
'backorders' => __( 'Backorders allowed?', 'woocommerce' ),
|
'backorders' => __( 'Backorders allowed?', 'woocommerce' ),
|
||||||
'sold_individually' => __( 'Sold individually?', 'woocommerce' ),
|
'sold_individually' => __( 'Sold individually?', 'woocommerce' ),
|
||||||
|
/* translators: %s: weight */
|
||||||
'weight' => sprintf( __( 'Weight (%s)', 'woocommerce' ), get_option( 'woocommerce_weight_unit' ) ),
|
'weight' => sprintf( __( 'Weight (%s)', 'woocommerce' ), get_option( 'woocommerce_weight_unit' ) ),
|
||||||
|
/* translators: %s: length */
|
||||||
'length' => sprintf( __( 'Length (%s)', 'woocommerce' ), get_option( 'woocommerce_dimension_unit' ) ),
|
'length' => sprintf( __( 'Length (%s)', 'woocommerce' ), get_option( 'woocommerce_dimension_unit' ) ),
|
||||||
|
/* translators: %s: width */
|
||||||
'width' => sprintf( __( 'Width (%s)', 'woocommerce' ), get_option( 'woocommerce_dimension_unit' ) ),
|
'width' => sprintf( __( 'Width (%s)', 'woocommerce' ), get_option( 'woocommerce_dimension_unit' ) ),
|
||||||
|
/* translators: %s: Height */
|
||||||
'height' => sprintf( __( 'Height (%s)', 'woocommerce' ), get_option( 'woocommerce_dimension_unit' ) ),
|
'height' => sprintf( __( 'Height (%s)', 'woocommerce' ), get_option( 'woocommerce_dimension_unit' ) ),
|
||||||
'reviews_allowed' => __( 'Allow customer reviews?', 'woocommerce' ),
|
'reviews_allowed' => __( 'Allow customer reviews?', 'woocommerce' ),
|
||||||
'purchase_note' => __( 'Purchase note', 'woocommerce' ),
|
'purchase_note' => __( 'Purchase note', 'woocommerce' ),
|
||||||
|
@ -199,6 +203,26 @@ class WC_Product_CSV_Exporter extends WC_CSV_Batch_Exporter {
|
||||||
return isset( $statuses[ $status ] ) ? $statuses[ $status ] : -1;
|
return isset( $statuses[ $status ] ) ? $statuses[ $status ] : -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get formatted sale price.
|
||||||
|
*
|
||||||
|
* @param WC_Product $product Product being exported.
|
||||||
|
* @return string
|
||||||
|
*/
|
||||||
|
protected function get_column_value_sale_price( $product ) {
|
||||||
|
return wc_format_localized_price( $product->get_sale_price( 'view' ) );
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get formatted regular price.
|
||||||
|
*
|
||||||
|
* @param WC_Product $product Product being exported.
|
||||||
|
* @return string
|
||||||
|
*/
|
||||||
|
protected function get_column_value_regular_price( $product ) {
|
||||||
|
return wc_format_localized_price( $product->get_regular_price() );
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get product_cat value.
|
* Get product_cat value.
|
||||||
*
|
*
|
||||||
|
@ -457,7 +481,9 @@ class WC_Product_CSV_Exporter extends WC_CSV_Batch_Exporter {
|
||||||
if ( $downloads ) {
|
if ( $downloads ) {
|
||||||
$i = 1;
|
$i = 1;
|
||||||
foreach ( $downloads as $download ) {
|
foreach ( $downloads as $download ) {
|
||||||
|
/* translators: %s: download number */
|
||||||
$this->column_names[ 'downloads:name' . $i ] = sprintf( __( 'Download %d name', 'woocommerce' ), $i );
|
$this->column_names[ 'downloads:name' . $i ] = sprintf( __( 'Download %d name', 'woocommerce' ), $i );
|
||||||
|
/* translators: %s: download number */
|
||||||
$this->column_names[ 'downloads:url' . $i ] = sprintf( __( 'Download %d URL', 'woocommerce' ), $i );
|
$this->column_names[ 'downloads:url' . $i ] = sprintf( __( 'Download %d URL', 'woocommerce' ), $i );
|
||||||
$row[ 'downloads:name' . $i ] = $download->get_name();
|
$row[ 'downloads:name' . $i ] = $download->get_name();
|
||||||
$row[ 'downloads:url' . $i ] = $download->get_file();
|
$row[ 'downloads:url' . $i ] = $download->get_file();
|
||||||
|
@ -482,9 +508,13 @@ class WC_Product_CSV_Exporter extends WC_CSV_Batch_Exporter {
|
||||||
if ( count( $attributes ) ) {
|
if ( count( $attributes ) ) {
|
||||||
$i = 1;
|
$i = 1;
|
||||||
foreach ( $attributes as $attribute_name => $attribute ) {
|
foreach ( $attributes as $attribute_name => $attribute ) {
|
||||||
|
/* translators: %s: attribute number */
|
||||||
$this->column_names[ 'attributes:name' . $i ] = sprintf( __( 'Attribute %d name', 'woocommerce' ), $i );
|
$this->column_names[ 'attributes:name' . $i ] = sprintf( __( 'Attribute %d name', 'woocommerce' ), $i );
|
||||||
|
/* translators: %s: attribute number */
|
||||||
$this->column_names[ 'attributes:value' . $i ] = sprintf( __( 'Attribute %d value(s)', 'woocommerce' ), $i );
|
$this->column_names[ 'attributes:value' . $i ] = sprintf( __( 'Attribute %d value(s)', 'woocommerce' ), $i );
|
||||||
|
/* translators: %s: attribute number */
|
||||||
$this->column_names[ 'attributes:visible' . $i ] = sprintf( __( 'Attribute %d visible', 'woocommerce' ), $i );
|
$this->column_names[ 'attributes:visible' . $i ] = sprintf( __( 'Attribute %d visible', 'woocommerce' ), $i );
|
||||||
|
/* translators: %s: attribute number */
|
||||||
$this->column_names[ 'attributes:taxonomy' . $i ] = sprintf( __( 'Attribute %d global', 'woocommerce' ), $i );
|
$this->column_names[ 'attributes:taxonomy' . $i ] = sprintf( __( 'Attribute %d global', 'woocommerce' ), $i );
|
||||||
|
|
||||||
if ( is_a( $attribute, 'WC_Product_Attribute' ) ) {
|
if ( is_a( $attribute, 'WC_Product_Attribute' ) ) {
|
||||||
|
@ -522,6 +552,7 @@ class WC_Product_CSV_Exporter extends WC_CSV_Batch_Exporter {
|
||||||
}
|
}
|
||||||
|
|
||||||
if ( $product->is_type( 'variable' ) && isset( $default_attributes[ sanitize_title( $attribute_name ) ] ) ) {
|
if ( $product->is_type( 'variable' ) && isset( $default_attributes[ sanitize_title( $attribute_name ) ] ) ) {
|
||||||
|
/* translators: %s: attribute number */
|
||||||
$this->column_names[ 'attributes:default' . $i ] = sprintf( __( 'Attribute %d default', 'woocommerce' ), $i );
|
$this->column_names[ 'attributes:default' . $i ] = sprintf( __( 'Attribute %d default', 'woocommerce' ), $i );
|
||||||
$default_value = $default_attributes[ sanitize_title( $attribute_name ) ];
|
$default_value = $default_attributes[ sanitize_title( $attribute_name ) ];
|
||||||
|
|
||||||
|
@ -566,6 +597,7 @@ class WC_Product_CSV_Exporter extends WC_CSV_Batch_Exporter {
|
||||||
}
|
}
|
||||||
|
|
||||||
$column_key = 'meta:' . esc_attr( $meta->key );
|
$column_key = 'meta:' . esc_attr( $meta->key );
|
||||||
|
/* translators: %s: meta data name */
|
||||||
$this->column_names[ $column_key ] = sprintf( __( 'Meta: %s', 'woocommerce' ), $meta->key );
|
$this->column_names[ $column_key ] = sprintf( __( 'Meta: %s', 'woocommerce' ), $meta->key );
|
||||||
$row[ $column_key ] = $meta_value;
|
$row[ $column_key ] = $meta_value;
|
||||||
$i ++;
|
$i ++;
|
||||||
|
|
Loading…
Reference in New Issue