Show custom price shortcode
The support doesn work on Saturdays and Sundays, so some Friday requests can be answered on Monday. If you have problems with registration ask help on contact us page pleaseIf you not got email within 24~36 business hours, firstly check your spam box, and if no any email from the support there - back to the forum and read answer here. DO NOT ANSWER ON EMAILS [noreply@pluginus.net] FROM THE FORUM!! Emails are just for your info, all answers should be published only here.
The support doesn work on Saturdays and Sundays, so some Friday requests can be answered on Monday.
Quote from ahelman on August 30, 2020, 15:40Hi
I'm currently using [woocs_show_custom_price value=xxx], which works great.
However, I now use that shortcode in multiple places with the same value provided. Which means if that value needs to be updated I need to remember to update the shortcode multiple times around the site, and I'm worried I'll forget one.
Is it possible that instead of a raw value it can also accept a woo product id instead (e.g. id=xxxx)? Then if I update the price in the product itself, the shortcodes used around the site will automatically also stay correct? (or is there another function or shortcode that does that I am unaware of)?
As an aside, I actually have my own shortcode that pulls the price from a woo product (as a raw integer, e.g. 3987), and I tried to nest that inside your shortcode, but that didn't work :-(
e.g. [woocs_show_custom_price value=[adz_product_price id="8167"][/woocs_show_custom_price]
Thanks in advance.
Hi
I'm currently using [woocs_show_custom_price value=xxx], which works great.
However, I now use that shortcode in multiple places with the same value provided. Which means if that value needs to be updated I need to remember to update the shortcode multiple times around the site, and I'm worried I'll forget one.
Is it possible that instead of a raw value it can also accept a woo product id instead (e.g. id=xxxx)? Then if I update the price in the product itself, the shortcodes used around the site will automatically also stay correct? (or is there another function or shortcode that does that I am unaware of)?
As an aside, I actually have my own shortcode that pulls the price from a woo product (as a raw integer, e.g. 3987), and I tried to nest that inside your shortcode, but that didn't work :-(
e.g. [woocs_show_custom_price value=[adz_product_price id="8167"][/woocs_show_custom_price]
Thanks in advance.
Quote from Pablo Borysenco on August 31, 2020, 11:42Hello
https://c2n.me/48UPMqb.png - of course this won't work
You need code customization
EXAMPLE:
<?php
$some_price = do_shortcode("[adz_product_price id="8167"]");
echo do_shortcode(" [woocs_show_custom_price value=".$some_price."]");
?>
Hello
https://c2n.me/48UPMqb.png - of course this won't work
You need code customization
EXAMPLE:
<?php
$some_price = do_shortcode("[adz_product_price id="8167"]");
echo do_shortcode(" [woocs_show_custom_price value=".$some_price."]");
?>
Quote from ahelman on August 31, 2020, 11:49Thanks for the reply.
So, presumably, I could wrap something like that sample code you supplied inside another manual shortcode - which I can then place around the site?
Thanks for the reply.
So, presumably, I could wrap something like that sample code you supplied inside another manual shortcode - which I can then place around the site?
Quote from Pablo Borysenco on September 1, 2020, 09:42Hello
I think yes - https://www.wpbeginner.com/wp-tutorials/how-to-add-a-shortcode-in-wordpress/
Hello
I think yes - https://www.wpbeginner.com/wp-tutorials/how-to-add-a-shortcode-in-wordpress/
Quote from ahelman on September 1, 2020, 12:35Ok - sorted it out myself in the end. Thanks for pointing me in the right direction! :-)
Code below in case you want to show it in your codex in the future.
/** * Shortcode for WooCommerce Product Price (to insert in various pages) * E.G. [adz_product_price id=8167] - where id is a woo product id. */ add_shortcode( 'adz_product_price', 'adz_woo_product_price_shortcode' ); function adz_woo_product_price_shortcode( $atts ) { $atts = shortcode_atts( array( 'id' => null ), $atts, 'adz_product_price' ); if ( empty( $atts[ 'id' ] ) ) { return ''; } $product_price = wc_get_product( $atts['id'] ); if ( ! $product_price ) { return ''; } $unrendered_price = $product_price->get_price(); // Price as plain number return do_shortcode( "[woocs_show_custom_price value=". $unrendered_price ."]" ); }
Ok - sorted it out myself in the end. Thanks for pointing me in the right direction! :-)
Code below in case you want to show it in your codex in the future.
/**
* Shortcode for WooCommerce Product Price (to insert in various pages)
* E.G. [adz_product_price id=8167] - where id is a woo product id.
*/
add_shortcode( 'adz_product_price', 'adz_woo_product_price_shortcode' );
function adz_woo_product_price_shortcode( $atts ) {
$atts = shortcode_atts( array(
'id' => null
), $atts, 'adz_product_price' );
if ( empty( $atts[ 'id' ] ) ) {
return '';
}
$product_price = wc_get_product( $atts['id'] );
if ( ! $product_price ) {
return '';
}
$unrendered_price = $product_price->get_price(); // Price as plain number
return do_shortcode( "[woocs_show_custom_price value=". $unrendered_price ."]" );
}Quote from Pablo Borysenco on September 2, 2020, 09:33Hello
Ok! Thank you for cooperation
Hello
Ok! Thank you for cooperation