Hello @fletcher_austin,
Are you referring to these two functions?
add_filter('cs_looper_custom_variations', function($result, $params) {
$product_id = $params['product_id'];
$product = wc_get_product($product_id);
if (!$product) {
return [];
}
if ('simple' === $product->get_type()) {
return [get_simple_product_data($product)]; // Return as an array of one to keep consistent with variations structure
}
// Handle variable products
if ('variable' === $product->get_type()) {
return get_variable_product_data($product);
}
// Return empty array if product type is neither simple nor variable
return [];
}, 10, 2);
function get_variable_product_data($product) {
$variations_data = [];
foreach ($product->get_children() as $child_id) {
$variation = wc_get_product($child_id);
if (!$variation || !$variation->is_in_stock() || '' === $variation->get_price()) {
continue;
}
// Fetching variation attributes
$variation_attributes = $variation->get_attributes();
$attributes_data = [];
$variation_attribute_names = [];
$variation_values = [];
foreach ($variation_attributes as $attribute => $value) {
$taxonomy = str_replace('attribute_pa_', '', $attribute);
$attribute_label = wc_attribute_label($taxonomy);
$value_name = '';
if (taxonomy_exists($taxonomy)) {
$term = get_term_by('slug', $value, $taxonomy);
$value_name = $term ? $term->name : $value;
} else {
$value_name = apply_filters('woocommerce_variation_option_name', $value);
}
$variation_attribute_names[$taxonomy] = $attribute_label;
$variation_values[$taxonomy] = $value_name;
}
// Fetching prices without HTML formatting
$original_price = $variation->get_regular_price();
$current_price = $variation->get_sale_price() ? $variation->get_sale_price() : $variation->get_price();
$variations_data[] = [
'id' => $variation->get_id(),
'sku' => $variation->get_sku(),
'name' => $variation->get_name(),
'image' => wp_get_attachment_url($variation->get_image_id()),
'add_to_cart_url' => htmlspecialchars_decode($variation->add_to_cart_url()),
'stock_quantity' => $variation->get_stock_quantity(),
'original_var_price' => wc_price($original_price),
'current_var_price' => wc_price($current_price),
'attribute_names' => $variation_attribute_names,
'variation_values' => $variation_values,
];
}
return $variations_data;
}
Be advised that custom PHP coding is beyond the scope of our support under our Support Policy. If you are unfamiliar with code and resolving potential conflicts, you may select our One service for further assistance.
Thanks.