Hooks & filters

Every action and filter the gallery provides, when it runs, and examples you can copy.

FreePro

Free: actions

ActionArgumentsWhen
siteryn_pgz_loaded$pluginAfter the plugin has booted (plugins_loaded), only when requirements are met
siteryn_pgz_upgrade$old_version (or false), $new_versionOn init (priority 20) when the stored version differs, i.e. after an update
siteryn_pgz_before_template · siteryn_pgz_after_template$template_name, $argsAround each gallery template; output becomes part of the gallery HTML
siteryn_pgz_settings_main_after$sectionGeneral tab, after the settings form
siteryn_pgz_settings_sidebar$sectionGeneral tab sidebar, after the Shortcode card

Free: filters

FilterArguments → returnUse
siteryn_pgz_settings_get_all$settings → arrayChange Free settings at runtime (not saved)
siteryn_pgz_locate_template$path, $template_name → stringFinal template path
siteryn_pgz_suppress_default_assets$suppress → boolSkip Free's CSS and JS on product pages (Pro uses it for its own styles)
shortcode_atts_siteryn_pgz_galleryWordPress coreShortcode attributes
siteryn_pgz_settings_sections · siteryn_pgz_settings_fields$sections / $fields → arrayAdd settings tabs and fields (read once per request)
siteryn_pgz_settings_nav_icon · _nav_sublabel · _nav_badge · _nav_visible · _description$value, $sectionA settings tab's icon, sublabel, badge, visibility and description
siteryn_pgz_settings_reset_actions$actions → arrayOption name ⇒ reset action, for the Reset card
siteryn_pgz_settings_save_redirect$redirect (false), $option_name → false or {tab, message?}Block a save and switch to another tab with a message
siteryn_pgz_admin_icons$icons → arrayAdmin icon set
siteryn_dashboard_plugins$plugins → array of {slug, title, icon}Plugin cards on the shared Siteryn → Welcome page (shared by Siteryn plugins)
siteryn_deactivation_feedback_endpoint$url → stringWhere the deactivation survey is sent (shared by Siteryn plugins)

Pro: actions

ActionArgumentsWhen
siteryn_pgz_pro_loaded$pluginAfter Pro has booted
siteryn_pgz_pro_upgrade$old_version, $new_versionOn init after a Pro update

Pro: filters

FilterShapeUse
siteryn_pgz_pro_available_styleskey ⇒ {label, pro, preview}The style list; each key also gets a [siteryn_pgz_pro_{key}] shortcode
siteryn_pgz_pro_style_templateskey ⇒ absolute pathThe template for each style
siteryn_pgz_pro_style_assetskey ⇒ {css: [], js: []}CSS and JS files for each style
shortcode_atts_siteryn_pgz_pro_{key}WordPress coreStyle shortcode attributes

Examples

Different settings for a category

add_filter( 'siteryn_pgz_settings_get_all', function ( $s ) {
	if ( is_admin() || ! did_action( 'wp' ) || ! is_product() ) {
		return $s; // settings are also read (and saved) in the admin
	}
	if ( has_term( 'posters', 'product_cat', get_queried_object_id() ) ) {
		$s['zoom_mode']          = 'lens';
		$s['thumbnail_position'] = 'top';
		$s['lightbox_enabled']   = false;
	}
	return $s;
} );

This covers Free's settings, which Pro styles share for zoom, arrows and the lightbox; Pro's per-style settings can't be filtered. gallery_enabled is read on init, before the product is known; to turn the gallery off per product, see the next example.

Keep WooCommerce's gallery for a category

add_action( 'wp', function () {
	if ( ! function_exists( 'is_product' ) || ! is_product() || ! has_term( 'bundles', 'product_cat', get_queried_object_id() ) ) {
		return;
	}
	$front = \Siteryn\SiterynProductGalleryZoom\Frontend::class;
	remove_action( 'woocommerce_before_single_product_summary', array( $front, 'render_gallery' ), 20 );
	remove_filter( 'render_block_woocommerce/product-image-gallery', array( $front, 'filter_gallery_block' ), 10 );
	add_action( 'woocommerce_before_single_product_summary', 'woocommerce_show_product_images', 20 );
	remove_filter( 'woocommerce_single_product_zoom_enabled', '__return_false' );
	remove_filter( 'woocommerce_single_product_photoswipe_enabled', '__return_false' );
	remove_filter( 'woocommerce_single_product_flexslider_enabled', '__return_false' );
	add_filter( 'siteryn_pgz_suppress_default_assets', '__return_true', 20 ); // 20: after Pro
	if ( class_exists( '\Siteryn\SiterynProductGalleryZoomPro\Assets' ) ) {
		remove_action( 'wp_enqueue_scripts', array( \Siteryn\SiterynProductGalleryZoomPro\Assets::class, 'enqueue' ) );
	}
} );

Change the image sizes

add_filter( 'woocommerce_gallery_image_size', fn() => 'large' );               // main image
add_filter( 'woocommerce_gallery_thumbnail_size', fn() => array( 200, 200 ) ); // thumbnails
add_filter( 'woocommerce_gallery_full_size', fn() => 'large' );                // zoom & lightbox

These are WooCommerce filters, so they also affect WooCommerce's own gallery.

Add markup after the gallery

add_action( 'siteryn_pgz_after_template', function ( $name, $args ) {
	if ( 'product-image.php' === $name && $args['product']->is_on_sale() ) {
		echo '<p class="my-gallery-note">' . esc_html__( 'Sale images', 'my-td' ) . '</p>';
	}
}, 10, 2 );

This prints after the gallery's wrapper, not inside it.

Add an image to a product's gallery

add_filter( 'woocommerce_product_get_gallery_image_ids', function ( $ids, $product ) {
	if ( ! is_admin() && 123 === $product->get_id() ) {
		$ids[] = 456; // attachment ID
	}
	return $ids;
}, 10, 2 );

There is no plugin filter on the image list; use WooCommerce's getter or a template override.

Hide a Pro style from the picker

add_filter( 'siteryn_pgz_pro_available_styles', function ( $styles ) {
	unset( $styles['masonry'] ); // also removes [siteryn_pgz_pro_masonry]
	return $styles;
} );

Add a settings tab

add_filter( 'siteryn_pgz_settings_sections', function ( $s ) {
	$s['my_ext'] = array( 'label' => 'My Extension', 'option_group' => 'my_ext_group', 'option_name' => 'my_ext_settings' );
	return $s;
} );
add_filter( 'siteryn_pgz_settings_fields', function ( $f ) {
	$f['my_ext_flag'] = array( 'section' => 'my_ext', 'group' => 'Main', 'type' => 'checkbox', 'label' => 'Flag', 'default' => false );
	return $f;
} );
// Also register_setting( 'my_ext_group', 'my_ext_settings', ... ) yourself.

Add these before the settings screen reads them: sections and fields are read once per request. Field types: checkbox, select, number, color, text, button_group and image.