xxxxxxxxxx
if ($product->is_type('variable')) {
// Get the available variations
$variations = $product->get_available_variations();
// Create separate arrays to store variations for each attribute
$session_variations = array();
$location_variations = array();
foreach ($variations as $variation) {
$attributes = $variation['attributes'];
// Check if the variation has the "pa_session" attribute
if (isset($attributes['attribute_pa_session'])) {
$session_variations[] = $variation;
}
// Check if the variation has the "pa_location" attribute
if (isset($attributes['attribute_pa_location'])) {
$location_variations[] = $variation;
}
}
// Now, you can display the variations for each attribute separately
echo '<div class="session-variations">';
echo '<h2>Session Variations</h2>';
foreach ($session_variations as $variation) {
// Display session variations here
// You can access the attributes of the variation using $variation['attributes']
// Customize this part to display the information you need
}
echo '</div>';
echo '<div class="location-variations">';
echo '<h2>Location Variations</h2>';
foreach ($location_variations as $variation) {
// Display location variations here
// You can access the attributes of the variation using $variation['attributes']
// Customize this part to display the information you need
}
echo '</div>';
}