Advertisement
lorro

WooCommerce - Complex price suffixes

Jan 9th, 2022
878
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 1.02 KB | None | 0 0
  1. <?php
  2.   // WooCommerce - Complex price suffixes
  3.   add_filter('woocommerce_get_price_suffix', 'custom_get_price_suffix', 90, 4 );
  4.   function custom_get_price_suffix( $html, $product, $price, $qty ) {
  5.     if ( ! $html && $product instanceof WC_Product_Variable ) {
  6.       // copied from woocommerce/includes/abstracts/abstract-wc-product.php#get_price_suffix
  7.       if ( ( $suffix = get_option( 'woocommerce_price_display_suffix' ) ) && wc_tax_enabled() && 'taxable' === $product->get_tax_status() ) {
  8.         $replacements = array(
  9.          '{price_including_tax}' => wc_price( wc_get_price_including_tax( $product, array( 'qty' => $qty, 'price' => $price ) ) ),
  10.          '{price_excluding_tax}' => wc_price( wc_get_price_excluding_tax( $product, array( 'qty' => $qty, 'price' => $price ) ) ),
  11.         );
  12.         $html = str_replace( array_keys( $replacements ), array_values( $replacements ), ' <small class="woocommerce-price-suffix">' . wp_kses_post( $suffix ) . '</small>' );
  13.       }
  14.     }
  15.     return $html;
  16.   } // end function
  17.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement