ASTRA_Ext_WooCommerce_Markup::sale_flash( mixed $markup, string $post, object $product )
Sale bubble flash
Description
Parameters
- $markup
-
(mixed) (Required) HTML markup of the the sale bubble / flash.
- $post
-
(string) (Required) Post.
- $product
-
(object) (Required) Product.
Return
(string) bubble markup.
Source
File: addons/woocommerce/classes/class-astra-ext-woocommerce-markup.php
public function sale_flash( $markup, $post, $product ) { $sale_notification = astra_get_option( 'product-sale-notification', '', 'default' ); $sale_percent_value = ''; // If none then return! if ( 'none' === $sale_notification ) { return; } // Default text. $text = __( 'Sale!', 'astra-addon' ); $sale_percentage_data = array(); switch ( $sale_notification ) { // Display % instead of "Sale!". case 'sale-percentage': $sale_percent_value = astra_get_option( 'product-sale-percent-value' ); // if not variable product. if ( ! $product->is_type( 'variable' ) ) { $sale_price = $product->get_sale_price(); if ( $sale_price ) { $regular_price = $product->get_regular_price(); $percent_sale = round( ( ( ( $regular_price - $sale_price ) / $regular_price ) * 100 ), 0 ); $sale_percent_value = $sale_percent_value ? $sale_percent_value : '-[value]%'; $text = str_replace( '[value]', $percent_sale, $sale_percent_value ); } } else { // if variable product. foreach ( $product->get_children() as $child_id ) { $variation = wc_get_product( $child_id ); if ( $variation instanceof WC_Product ) { // Checking in case if the wc_get_product exists or is not false. $sale_price = $variation->get_sale_price(); if ( $sale_price ) { $regular_price = $variation->get_regular_price(); $percent_sale = round( ( ( ( $regular_price - $sale_price ) / $regular_price ) * 100 ), 0 ); $sale_percent_value = $sale_percent_value ? $sale_percent_value : '-[value]%'; $text = str_replace( '[value]', $percent_sale, $sale_percent_value ); $sale_percentage_data[ $child_id ] = $percent_sale; } } } } break; } // CSS classes. $classes = array(); $classes[] = 'onsale'; $classes[] = astra_get_option( 'product-sale-style' ); $classes = implode( ' ', $classes ); // Generate markup. return '<span ' . astra_attr( 'woo-sale-badge-container', array( 'class' => $classes, 'data-sale' => wp_json_encode( $sale_percentage_data ), 'data-notification' => $sale_notification, 'data-sale-per-text' => $sale_percent_value, ) ) . '>' . esc_html( $text ) . '</span>'; }
Expand full source code Collapse full source code View on Trac