Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- add_shortcode( 'woo_product_price', function($atts) {
- global $post;
- $atts = shortcode_atts( array(
- 'id' => null,
- ), $atts, 'woo_product_price' );
- $html = '';
- if( intval( $atts['id'] ) > 0 && function_exists( 'wc_get_product' ) ){
- $product = wc_get_product( intval( $atts['id'] ) );
- } elseif( is_product() ) {
- $product = wc_get_product($post);
- }
- if ( ! is_a( $product, 'WC_Product' ) ) return;
- // Get the product prices
- $price = wc_get_price_to_display( $product, array( 'price' => $product->get_price() ) ); // Get the active price
- $regular_price = wc_get_price_to_display( $product, array( 'price' => $product->get_regular_price() ) ); // Get the regular price
- $sale_price = wc_get_price_to_display( $product, array( 'price' => $product->get_sale_price() ) ); // Get the sale price
- // Your price CSS styles
- $style1 = 'style="font-size:40px;color:#e79a99;font-weight:bold;"';
- $style2 = 'style="font-size:25px;color:#e79a99"';
- // Formatting html output
- if( ! empty( $sale_price ) && $sale_price != 0 && $sale_price < $regular_price )
- $html = "<del $style2>" . wc_price( $regular_price ) . "</del> <ins $style1>" . wc_price( $sale_price ) . "</ins>"; // Sale price is set
- else
- $html = "<ins $style1>" . wc_price( $price ) . "</ins>"; // No sale price set
- return $html;
- });
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement