Hi Andrew,
Unfortunately, the feature is not currently available.
But it’s a great idea. I’ll discuss this feature with my team.
In the meantime, please send the feature request here: https://storepress.fider.io/
and ask your other to upvote it.
Cheers!
Change gallery width for some products
Andrew Taylor
Hi,
Is there a function or js I can add to set the gallery width to say 70% only for a selection of products.
Most products have a 100% width gallery but I have some products with extra custom options (YITH Product Add ons plugin) in the product details column which get very squashed. I already have a function that looks to see if the YITH custom options are used (adds a class to the body tag) so I can add the gallery width 70% change in there.
//show the following class in the body .yith-wapo-has-addons
if( !function_exists(‘yith_wapo_add_class_if_addons_in_product’) && function_exists(‘yith_wapo_get_blocks’) ) {
function yith_wapo_add_class_if_addons_in_product($class)
{
if ( is_product() ) {
global $post, $variation;
if ($post) {
$product = wc_get_product($post);
if ($product) {
$product_id = apply_filters(‘yith_wapo_get_original_product_id’, $product->get_id());
$variation_id = $variation instanceof WC_Product_Variation ? apply_filters(‘yith_wapo_get_original_product_id’, $variation->get_id()) : ”;
$product_categories = apply_filters(‘yith_wapo_get_original_category_ids’, $product->get_category_ids(), $product, $product_id);
foreach (yith_wapo_get_blocks() as $key => $block) {
if (‘1’ === $block->visibility) {
$show_in = $block->get_rule(‘show_in’);
$included_product_check = in_array((string)$product_id, (array)$block->get_rule(‘show_in_products’), true);
if (!$included_product_check && !empty($variation_id)) {
$included_product_check = in_array((string)$variation_id, (array)$block->get_rule(‘show_in_products’), true);
}
$included_category_check = count(array_intersect((array)$block->get_rule(‘show_in_categories’), $product_categories)) > 0;
$exclude_in = $block->get_rule(‘exclude_products’);
$excluded_product_check = in_array((string)$product_id, (array)$block->get_rule(‘exclude_products_products’), true);
if (!$excluded_product_check && !empty($variation_id)) {
$excluded_product_check = in_array((string)$variation_id, (array)$block->get_rule(‘show_in_products’), true);
}
$excluded_categories_check = ‘all’ === $show_in && count(array_intersect((array)$block->get_rule(‘exclude_products_categories’), $product_categories)) > 0;
$show_to = $block->get_rule(‘show_to’);
$show_to_user_roles = $block->get_rule(‘show_to_user_roles’);
$show_to_membership = $block->get_rule(‘show_to_membership’);
$vendor_check = true;
if ($block->vendor_id > 0 && function_exists(‘yith_get_vendor’)) {
$vendor = yith_get_vendor($product_id, ‘product’);
if ($vendor->is_valid()) {
$vendor_check = (string)$block->vendor_id === (string)$vendor->id;
} else {
$vendor_check = false;
}
}
// Vendor.
if ($vendor_check) {
// Include.
if ((‘all’ === $show_in) || (‘products’ === $show_in && ($included_product_check || $included_category_check))) {
// Exclude.
if (‘yes’ !== $exclude_in || (!$excluded_product_check && !$excluded_categories_check)) {
// Show to.
if (
” === $show_to
|| ‘all’ === $show_to
|| (‘guest_users’ === $show_to && !is_user_logged_in())
|| (‘logged_users’ === $show_to && is_user_logged_in())
|| (‘user_roles’ === $show_to && count(array_intersect((array)$show_to_user_roles, (array)wp_get_current_user()->roles)) > 0)
|| (‘membership’ === $show_to && yith_wcmbs_user_has_membership(get_current_user_id(), $show_to_membership))
) {
$addons = yith_wapo_get_addons_by_block_id($block->id);
$total_addons = count($addons);
if ($total_addons > 0) {
//move product title above gallery image
remove_action( ‘woocommerce_single_product_summary’, ‘woocommerce_template_single_title’, 5 );
add_action( ‘woocommerce_before_single_product’, ‘woocommerce_template_single_title’, 5 );
$class = array_merge($class, array(‘yith-wapo-has-addons’));
break;
}
}
}
}
}
}
}
}
}
}
return $class;
}
add_filter(‘body_class’, ‘yith_wapo_add_class_if_addons_in_product’);
}
Thanks
Andrew