Skip to content

Instantly share code, notes, and snippets.

@lil5
Created March 27, 2021 16:21
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save lil5/3f8913a8290b260b5f831f7f0f89e119 to your computer and use it in GitHub Desktop.
Save lil5/3f8913a8290b260b5f831f7f0f89e119 to your computer and use it in GitHub Desktop.
Shortcode WooCommerce Product Price.
<?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