Created
August 19, 2020 07:30
-
-
Save AchalJ/1fcbecabc4798922fa2c584faa36b8e0 to your computer and use it in GitHub Desktop.
Shortcode to get WooCommerce Product Price
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
add_shortcode( 'woo_wc_get_product_price', function( $args ) { | |
if ( ! isset( $args['id'] ) || empty( absint( $args['id'] ) ) ) { | |
return; | |
} | |
if ( ! function_exists( 'wc_get_product' ) ) { | |
return; | |
} | |
$id = absint( $args['id'] ); | |
$product = wc_get_product( $id ); | |
if ( ! $product || is_wp_error( $product ) ) { | |
return; | |
} | |
return $product->get_price(); | |
} ); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment