Skip to content

Commit

Permalink
Fix: Fatal error when exporting products. String was treated as array.
Browse files Browse the repository at this point in the history
```
Uncaught TypeError: implode(): Argument twoelevenjay#2 ($array) must be of type ?array, string given in /path/to/wp-content/plugins/woocommerce-discontinued-products/includes/class-dp-csv-import-export.php:156
Stack trace:
#0 /path/to/wp-content/plugins/woocommerce-discontinued-products/includes/class-dp-csv-import-export.php(156): implode(', ', '')
twoelevenjay#1 /path/to/wp-includes/class-wp-hook.php(309): DP_CSV_Import_Export->add_export_data_alt_products('', Object(WC_Product_Simple))
twoelevenjay#2 /path/to/wp-includes/plugin.php(191): WP_Hook->apply_filters('', Array)
twoelevenjay#3 /path/to/wp-content/plugins/woocommerce/includes/export/class-wc-product-csv-exporter.php(232): apply_filters('woocommerce_pro...', '', Object(WC_Product_Simple), 'alt_products')
twoelevenjay#4 /path/to/wp-content/plugins/woocommerce/includes/export/class-wc-product-csv-exporter.php(185): WC_Product_CSV_Exporter->generate_row_data(Object(WC_Product_Simple))
twoelevenjay#5 /path/to/wp-content/plugins/woocommerce/includes/export/abstract-wc-csv-batch-exporter.php(117): WC_Product_CSV_Exporter->prepare_data_to_export()
twoelevenjay#6 /path/to/wp-content/plugins/woocommerce/includes/admin/class-wc-admin-exporters.php(165): WC_CSV_Batch_Exporter->generate_file()
twoelevenjay#7 /path/to/wp-includes/class-wp-hook.php(307): WC_Admin_Exporters->do_ajax_product_export('')
twoelevenjay#8 /path/to/wp-includes/class-wp-hook.php(331): WP_Hook->apply_filters('', Array)
twoelevenjay#9 /path/to/wp-includes/plugin.php(476): WP_Hook->do_action(Array)
twoelevenjay#10 /path/to/wp-admin/admin-ajax.php(187): do_action('wp_ajax_woocomm...')
twoelevenjay#11 {main}
  thrown
```
  • Loading branch information
BrianHenryIE committed Aug 4, 2022
1 parent 1a41470 commit b51a6ed
Showing 1 changed file with 3 additions and 2 deletions.
5 changes: 3 additions & 2 deletions includes/class-dp-csv-import-export.php
Original file line number Diff line number Diff line change
Expand Up @@ -152,8 +152,9 @@ public function add_export_data_discontinued_product_text( $value, $product ) {
* @return mixed $value Should be in a format that can be output into a text file (string, numeric, etc).
*/
public function add_export_data_alt_products( $value, $product ) {
$value = $product->get_meta( '_alt_products', true, 'edit' );
return implode( ', ', $value );
$meta_data = $product->get_meta( '_alt_products', false, 'edit' );
$values = wp_list_pluck( $meta_data, 'value' );
return implode( ', ', $values );
}

/**
Expand Down

0 comments on commit b51a6ed

Please sign in to comment.