Regular and Sales Prices in WooCommerce as Shortcode
-
Hello
I would like to be able to insert regular price (and sales price) in to a custom product template as a shortcode. I wont therefore be able to manually input product ids.
I found the below code but could not get it to work. Any assistance is appreciated.
function so_30165014_price_shortcode_callback( $atts ) { $atts = shortcode_atts( array( 'id' => null, ), $atts, 'bartag' ); $html = ''; if( intval( $atts['id'] ) > 0 && function_exists( 'wc_get_product' ) ){ $_product = wc_get_product( $atts['id'] ); $html = "price = " . $_product->get_price(); } return $html; } add_shortcode( 'woocommerce_price', 'so_30165014_price_shortcode_callback' );
Viewing 7 replies - 1 through 7 (of 7 total)
Viewing 7 replies - 1 through 7 (of 7 total)
- The topic ‘Regular and Sales Prices in WooCommerce as Shortcode’ is closed to new replies.