Skip to content

Instantly share code, notes, and snippets.

@init90
Created September 20, 2020 08:26
Show Gist options
  • Save init90/29ade76dc9e0d49878e2e9f8f5d7a62f to your computer and use it in GitHub Desktop.
Save init90/29ade76dc9e0d49878e2e9f8f5d7a62f to your computer and use it in GitHub Desktop.
Hide price field for specific view mode.
/**
* Implements hook_ENTITY_TYPE_view_alter() for 'commerce_product' entities.
*/
function swimsports_commerce_commerce_product_view_alter(array &$build, EntityInterface $node, EntityViewDisplayInterface $display) {
// Hide price field. For some reason we cannot configure price visibility
// from UI.
if ($build['#view_mode'] === 'add_to_cart_confirmation_view') {
$build['variation_price']['#access'] = FALSE;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment