V
V
Vasilek_132021-08-17 19:44:12
WordPress
Vasilek_13, 2021-08-17 19:44:12

How do I add my data to the standard CSV export in WooCommerce?

Hello! There is a task to add a link to the product page in the standard WooCommerce export.
I already found how to implement it on the WP-Kama website, but I just can’t get a link to the product. Neither get_the_permalink() nor the_permalink() help: either empty or 0.
Here is a sample code:

add_filter( 'woocommerce_product_export_product_default_columns', 'add_columns_to_wc_csv_export' );
/**
 * Регистрирует новую колонку для экспорта. На данном этапе все отрабатывает.
 *
 * @param string[] $column_names
 *
 * @return string[]
 */
function add_columns_to_wc_csv_export( $column_names ) {
  $column_names['key_my_field'] = 'Ссылка на товар';
  return $column_names;
}

add_filter( 'woocommerce_product_export_product_column_key_my_field', 'add_data_to_wc_export', 10, 2 );

/**
 * Заполняет новую колонку данными. Тут уже не срабатывает и данные в экспорт не передает.
 *
 * @param mixed      $value (По умолчанию: '')
 * @param WC_Product $product
 *
 * @return mixed
 */
function add_data_to_wc_export( $value, $product ) {
  $value = get_the_permalink();
  return $value;
}


Pliz help!!! What's wrong?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
V
Vasilek_13, 2021-08-17
@Vasilek_13

Damn hurried with the question)))
Everything is extremely simple instead of get_the_permalink() you need $product->get_permalink()

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question