Skip to content

Instantly share code, notes, and snippets.

@pramodjodhani
Created October 10, 2025 07:50
Show Gist options
  • Save pramodjodhani/742af7428577a3f159714164195773be to your computer and use it in GitHub Desktop.
Save pramodjodhani/742af7428577a3f159714164195773be to your computer and use it in GitHub Desktop.
LV - Add custom buttons to Linked variation
<?php
add_filter( 'iconic_wlv_group_data', 'iconic_lv_add_custom_linked_variations', 10, 2 );
function iconic_lv_add_custom_linked_variations( $group_data, $product_id ) {
// Todo1. Add the actual linked variation ID here
$linked_variation_id = 93;
if ( $group_data['group']->post->ID !== $linked_variation_id ) {
return $group_data;
}
// Todo2: Add the list of buttons to add to the Linked Variations group.
$to_add = array(
array(
'label' => 'Water green',
'ID' => 91
),
array(
'label' => 'Pink',
'ID' => 94
),
);
// ------------------------------------------------------------
// Stop editing.
// ------------------------------------------------------------
$prepared_terms = array();
foreach ($to_add as $color) {
$url = get_permalink($color['ID']);
$prepared_terms[$color['label']] = array(
'label' => $color['label'],
'current' => false,
'url' => $url,
'content' => "<a
href='$url'
title='{$color['label']}'
class='iconic-wlv-terms__term-content iconic-wlv-terms__term-content--link'>
{$color['label']}
</a>",
'has_image' => false,
'linked_variation_data' => array(
'match' => true,
'variation' => array(
'permalink' => get_permalink($color['ID']),
'title' => $color['label'],
'stock_status' => 'instock',
'purchasable' => true,
)
)
);
}
$group_data['attributes']['pa_color']['terms'] = array_merge($group_data['attributes']['pa_color']['terms'], $prepared_terms);
return $group_data;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment