Skip to content

Instantly share code, notes, and snippets.

@AchalJ
Created August 19, 2020 07:30
Show Gist options
  • Save AchalJ/1fcbecabc4798922fa2c584faa36b8e0 to your computer and use it in GitHub Desktop.
Save AchalJ/1fcbecabc4798922fa2c584faa36b8e0 to your computer and use it in GitHub Desktop.
Shortcode to get WooCommerce Product Price
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