Compatibility with themes
Some themes doesn’t support Woocommerce hooks, so you should add shortcodes [adp_category_bulk_rules_table] and [adp_product_bulk_rules_table] to necessary page templates (or directly to product description) OR you can submit new ticket to helpdesk.
If you use paid plugin/theme — please, upload it (as.zip file) to the ticket!
Flatsome:
If the percentage badge doesn’t display, you need to go to Appearance > Themes > Flatsome > Customize > WooCommerce > Product catalog and enable the “Enable % instead of “Sale!” parameter (at the bottom of the list).
Divi:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 |
add_filter( 'woocommerce_sale_flash', 'add_percentage_to_sale_badge', 20, 3 ); function add_percentage_to_sale_badge( $html, $post, $product ) { if ( $product->is_type( 'grouped' ) || $product->is_type( 'variable' ) ) { $percentages = array(); foreach ( $product->get_children() as $childId ) { $childProduct = wc_get_product( $childId ); $regularPrice = floatval( $childProduct->get_regular_price() ); if ( $regularPrice === floatval( 0 ) ) { $percentages[] = floatval( 100 ); break; } $salePrice = $childProduct->get_sale_price() !== "" ? floatval( $childProduct->get_sale_price() ) : null; if ( $salePrice !== null ) { // Calculate and set in the array the percentage for each child on sale $percentages[] = round( 100 - ( $salePrice / $regularPrice * 100 ) ); } } // We keep the highest value $percentage = count( $percentages ) > 0 ? max( $percentages ) . '%' : ""; } else { $regularPrice = floatval( $product->get_regular_price() ); if ( $regularPrice !== floatval( 0 ) ) { $salePrice = $product->get_sale_price() !== "" ? floatval( $product->get_sale_price() ) : null; if ( $salePrice !== null ) { $percentage = round( 100 - ( $salePrice / $regularPrice * 100 ) ) . '%'; } else { return $html; } } else { $percentage = floatval( 100 ) . '%'; } } return '<span class="onsale">' . esc_html__( 'SALE', 'woocommerce' ) . ' ' . $percentage . '</span>'; } |
If the “Update price when user changes qty” parameter doesn’t work in the Divi theme you need to use the following code:
1 2 3 4 5 6 7 8 9 10 11 |
add_action( 'wp_footer', function() { ?> <script> jQuery( document ).ready( function() { setTimeout( function() { dynamicPrices[0].addPriceDestination("#page-container p.price"); }, 1000 ); }); </script> <?php }); |