Created
March 27, 2021 16:21
-
-
Save lil5/3f8913a8290b260b5f831f7f0f89e119 to your computer and use it in GitHub Desktop.
Shortcode 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
<?php | |
/* | |
Plugin Name: LI Woo Shortcode | |
Plugin URI: http://li.last.nl | |
Description: Add Product Price in WooCommerce as a Shortcode | |
Version: 1.0 | |
Author: Lucian I. Last | |
Author URI: https://li.last.nl | |
License: GPL2 | |
*/ | |
add_shortcode( 'cl_product_price', 'cl_woo_product_price_shortcode' ); | |
/** | |
* Shortcode WooCommerce Product Price. | |
* https://wpbeaches.com/add-woocommerce-product-price-as-a-shortcode/ | |
*/ | |
function cl_woo_product_price_shortcode( $atts ) { | |
$atts = shortcode_atts( array( | |
'id' => null | |
), $atts, 'cl_product_price' ); | |
if ( empty( $atts[ 'id' ] ) ) { | |
return ''; | |
} | |
$product = wc_get_product( $atts['id'] ); | |
if ( ! $product ) { | |
return ''; | |
} | |
return $product->get_price_html(); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment