List of available plugin php hooks.
Hook | Type | Description |
---|---|---|
awl_labels_output | filter | Labels container HTML markup for each WooCommerce product |
awl_show_label_for_product | filter | Show or not label on current product |
awl_show_labels_for_product | filter | Show or not all available labels for the current product. |
awl_label_markup | filter | Labels HTML markup for each WooCommerce product on certain position type |
awl_current_label_markup | filter | Single label HTML markup for the current WooCommerce product |
awl_label_container_styles | filter | Filter labels container styles |
awl_label_wrapper_styles | filter | Filter label wrapper styles |
awl_label_styles | filter | Filter label block styles |
awl_label_text_styles | filter | Filter label inner styles |
awl_labels_text_vars | filter | Filter label text variables |
awl_labels_hooks | filter | Filter label hooks that used to display labels |
awl_js_selectors | filter | Filter js selectors for labels |
awl_js_container_selectors | filter | Filter js selectors for product container |
awl_get_labels | filter | Get and filter all available labels IDs |
awl_svg_icons | filter | Filter label svg icons |
awl_label_rules | filter | Admin hook. Filter label condition rules option |
awl_labels_positions | filter | Admin hook. Display labels positions options |
awl_woocommerce_hooks | filter | Admin hook. Filter standard WooCommerce hooks |
awl_admin_page_options | filter | Admin hook. Filter options array for the plugin settings page. |
awl_label_admin_options | filter | Admin hook. Filter label options array. |
apply_filters( 'awl_labels_output', (string) $label_html, (string) $label_position_type );
Labels container HTML markup for each WooCommerce product. Container can have several labels inside.
Lets wrap labels output with .labels-wrapper
div block.
add_filter( 'awl_labels_output', 'my_awl_labels_output', 10, 2 ); function my_awl_labels_output( $label_html, $label_position_type ) { $label_html = '<div class="labels-wrapper">' . $label_html . '</div>'; return $label_html; }
apply_filters( 'awl_show_label_for_product', (bool) $show, (object) $product, (int) $label_id );
Show or not label for current product.
Lets add the following rule: Hide for product with ID 123
lables with IDs 5
, 7
and 8
.
add_filter( 'awl_show_label_for_product', 'my_awl_show_label_for_product', 10, 3 ); function my_awl_show_label_for_product( $show, $product, $label_id ) { $labels_to_exclude = array( 5, 7, 8 ); if ( $product->get_id() === 123 && in_array( $label_id, $labels_to_exclude ) ) { return false; } return $show; }
apply_filters( 'awl_show_labels_for_product', (bool) $disable_labels, (object) $product );
Show or not all available labels for the current product.
Hide all labels for products with IDs 1
, 2
and 3
.
add_filter( 'awl_show_labels_for_product', 'my_awl_show_labels_for_product', 10, 2 ); function my_awl_show_labels_for_product( $disable_labels, $product ) { $hide_for_products = array( 1, 2, 3 ); if ( in_array( $product->get_id(), $hide_for_products ) ) { return true; } return $disable_labels; }
apply_filters( 'awl_label_markup', (string) $html, (string) $position_type, (array) $labels );
Labels HTML markup for each WooCommerce product on certain position type.
Lets wrap labels output with .labels-wrapper
div block.
add_filter( 'awl_label_markup', 'my_awl_label_markup', 10, 3 ); function my_awl_label_markup( $html, $position_type, $labels ) { $html = '<div class="labels-wrapper">' . $html . '</div>'; return $html; }
apply_filters( 'awl_current_label_markup', (string) $html, (string) $position_type, (array) $label );
Single label HTML markup for the current WooCommerce product
Lets wrap label with the custom link https://my-link.com
for the current label.
add_filter( 'awl_current_label_markup', 'my_awl_current_label_markup', 10, 3 ); function my_awl_current_label_markup( $html, $position_type, $label ) { $link = 'https://my-link.com'; $link = '<object><a href="' . $link . '"'; $html = str_replace( '<div', $link, $html ); $html = str_replace( '</div>', '</a></object>', $html ); return $html; }
apply_filters( 'awl_label_container_styles', (array) $styles, (string) $position_type, (array) $labels );
Filter labels container styles before output. Containers can have one or more labels inside.
Change container position
style to relative
if position type is on_image
.
add_filter( 'awl_label_container_styles', 'my_awl_label_container_styles', 10, 3 ); function my_awl_label_container_styles( $styles, $position_type, $labels ) { if ( $position_type === 'on_image' ) { $styles['position'] = 'relative'; $styles['z-index'] = '0'; } return $styles; }
apply_filters( 'awl_label_wrapper_styles', (array) $styles, (string) $position_type, (array) $settings );
Filter label wrapper styles before output.
Add new style margin: 10px
for labels wrapper.
add_filter( 'awl_label_wrapper_styles', 'my_awl_label_wrapper_styles', 10, 3 ); function my_awl_label_wrapper_styles( $styles, $position_type, $settings ) { $styles['margin'] = '10px'; return $styles; }
apply_filters( 'awl_label_styles', (array) $styles, (string) $position_type, (array) $settings );
Filter label block styles before output. Overwrites label settings that were specified from the label edit page.
Change font color and size for all labels.
add_filter( 'awl_label_styles', 'my_awl_label_styles', 10, 3 ); function my_awl_label_styles( $styles, $position_type, $settings ) { $styles['color'] = '#000'; $styles['font-size'] = '12px'; return $styles; }
apply_filters( 'awl_label_text_styles', (array) $styles, (string) $position_type, (array) $settings );
Filter label inner styles before output. Overwrites label settings that were specified from the label edit page.
Change label background color for Shop
page only.
add_filter( 'awl_label_text_styles', 'my_awl_label_text_styles', 10, 3 ); function my_awl_label_text_styles( $styles, $position_type, $settings ) { if ( is_shop() ) { $styles['background'] = '#ff0000'; } return $styles; }
apply_filters( 'awl_labels_text_vars', (array) $variables );
Filter label text variables.
Lets add a new text variable {DOUBLE_PRICE}
that will show product price multiplied by 2.
add_filter( 'awl_labels_text_vars', 'my_awl_labels_text_vars' ); function my_awl_labels_text_vars( $variables ) { $variables['/{DOUBLE_PRICE}/i'] = array( 'func' => 'awl_double_price_show' ); return $variables; } function awl_double_price_show() { global $product; $price = $product->get_price() * 2; return $price; }
apply_filters( 'awl_labels_hooks', (array) $hooks );
Filter label hooks that used to display labels.
Default plugin hooks work fine with almost all WordPress themes but sometimes it is still necessary to change some default hooks to display labels. Let's change the hook that used to display labels on shop/archive pages for on_image
position.
add_filter( 'awl_labels_hooks', 'my_awl_labels_hooks' ); function my_awl_labels_hooks( $hooks ) { $hooks['on_image']['archive'] = array( 'woocommerce_before_shop_loop_item' => array( 'priority' => 10 ) ); return $hooks; }
apply_filters( 'awl_js_selectors', (array) $selectors );
Filter js selectors for labels. JS selectors can be used when it is not possible to display labels with standard php hooks. For example, when a certain theme just doesn't support any of the product hooks.
Lets display labels via JS for products archive pages. To use js hook only for archive pages we will use selector .awl-label-type-archive
. Second argument - array that specify where to add these labels relative to product blocks. For example, in our theme we have block .et_shop_image
and want to append labels inside it.§
It is possible to use append
, prepend
, before
and after
to describe how labels must be added relative to the selected box.
add_filter( 'awl_js_selectors', 'my_awl_js_selectors' ); function my_awl_js_selectors( $selectors ) { $selectors['.awl-label-type-archive'] = array( '.et_shop_image', 'append' ); return $selectors; }
apply_filters( 'awl_js_container_selectors', (array) $product_container );
Filter js selectors for product container. Use it with awl_js_selectors
filter to detect the right product container selector. By default it is .product
but some themes or plugins can change this default value.
If you are using awl_js_selectors
filter to display labels and fail with it please check that each product item is inside a container with class name product
. If it is not true then you need to specify an additional selector for the product container. For example, for JetWooBuilder For Elementor plugin blocks correct product container selector will be [data-product-id]
.
add_filter( 'awl_js_container_selectors', 'my_awl_js_container_selectors' ); function my_awl_js_container_selectors( $container ) { if ( class_exists( 'Jet_Woo_Builder' ) ) { $container[] = '[data-product-id]'; } return $container; }
apply_filters( 'awl_get_labels', (array) $labels );
Filter all published labels IDs. Used each time when labels displayed on the pages.
We can, for example, remove label with ID 8158
from the Shop
page.
add_filter( 'awl_get_labels', 'my_awl_get_labels' ); function my_awl_get_labels( $labels ) { if ( is_shop() ) { $label_key = array_search( '8158', $labels ); unset( $labels[$label_key] ); } return $labels; }
apply_filters( 'awl_svg_icons', (array) $icons );
Filter labels svg icons that are used for labels shapes.
Change svg for one of the icons.
add_filter( 'awl_svg_icons', 'my_awl_svg_icons' ); function my_awl_svg_icons( $icons ) { $icons['angle-after'] = '<g class="awl-triangled-after"><polygon vector-effect="non-scaling-stroke" points="0,0 0,100 97,50" style="stroke:none;" /><line vector-effect="non-scaling-stroke" x1="0" y1="0" x2="97" y2="50" /><line vector-effect="non-scaling-stroke" x1="97" y1="50" x2="0" y2="100" /></g>'; return $icons; }
apply_filters( 'awl_label_rules', (array) $rules );
Admin hook. Filter label condition rules option. Only for the admin area.
Add a new rule called Some custom value
inside the label edit page.
add_filter( 'awl_label_rules', 'my_awl_label_rules' ); function my_awl_label_rules( $rules ) { $rules['attributes'][] = array( "name" => __( "Some custom value", "advanced-woo-labels" ), "id" => "custom_value", "type" => "number", "operators" => "equals_compare", ); return $rules; }
apply_filters( 'awl_labels_positions', (array) $positions );
Admin area hook. Filter available labels positions before displaying inside label hooks table for settings page.
Create new labels position after_title
and display it for label settings page.
add_filter( 'awl_labels_positions', 'my_awl_labels_positions' ); function my_awl_labels_positions( $positions ) { $positions[] = array( 'slug' => 'after_title', 'name' => __( 'After title', 'advanced-woo-labels' ) ); return $positions; }
apply_filters( 'awl_woocommerce_hooks', (array) $hooks );
Admin area hook. Filter standard WooCommerce hooks that are used for hooks table inside the plugin settings page.
Remove woocommerce_before_shop_loop_item
hook from the list of default WooCommerce hooks.
add_filter( 'awl_woocommerce_hooks', 'my_awl_woocommerce_hooks' ); function my_awl_woocommerce_hooks( $hooks ) { $hook_key = array_search( 'woocommerce_before_shop_loop_item', $hooks ); unset( $hooks[$hook_key] ); return $hooks; }
apply_filters( 'awl_admin_page_options', (array) $options );
Admin area hook. Filter options array for the plugin settings page.
Lets add a new option called show_on_mobile
. When disable it will hide all product labels on mobile devices. In this example we will use additional hook awl_show_label_for_product
to hide labels when this new option is set to Hide
.
add_filter( 'awl_admin_page_options', 'my_awl_admin_page_options' ); function my_awl_admin_page_options( $options ) { $options['general'][] = array( "name" => __( "Show on mobile", "advanced-woo-labels" ), "desc" => __( "Show or not labels on mobile devices.", "advanced-woo-labels" ), "id" => "show_on_mobile", "value" => 'true', "type" => "select", 'choices' => array( 'true' => __( 'Show', 'advanced-woo-labels' ), 'false' => __( 'Hide', 'advanced-woo-labels' ), ) ); return $options; } add_filter( 'awl_show_label_for_product', 'my_awl_show_label_for_product' ); function my_awl_show_label_for_product( $match_condition ) { if ( wp_is_mobile() && AWL()->get_settings( 'show_on_mobile' ) === 'false' ) { return false; } return $match_condition; }
apply_filters( 'awl_label_admin_options', (array) $options );
Admin area hook. Filter label options array.
Add a new option called label_link
that will be visible inside the label edit page. This will be a simple text field type. When specified it will be saved to the label meta field _awl_label
along with the other label options and can be used for some other label customizations.
add_filter( 'awl_label_admin_options', 'my_awl_label_admin_options' ); function my_awl_label_admin_options( $options ) { $options['general'][] = array( "name" => __( "Label link", "advanced-woo-labels" ), "id" => "label_link", "value" => '', "type" => "text", ); return $options; }