<?php

if ( ! defined( 'ABSPATH' ) ) {
	exit;
}

/**
 * Get all Product category for meta value
 * @param $term_slug
 *
 * @return array|bool
 */

function dpcd_options_taxonomy_terms() {
    $cached = get_transient('dpcd_product_cat_options');
    if ($cached !== false) {
        return $cached;
    }

    $terms = get_terms([
        'taxonomy'   => 'product_cat',
        'hide_empty' => false,
    ]);

    if (is_wp_error($terms) || empty($terms)) {
        return [];
    }

    $result = [];
    foreach ($terms as $term) {
        $result[$term->slug] = $term->name;
    }

    set_transient('dpcd_product_cat_options', $result, HOUR_IN_SECONDS);

    return $result;
}
