Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save hamidrezayazdani/dcdc501c55aac1ed145b2dbd7a15aa9f to your computer and use it in GitHub Desktop.
Save hamidrezayazdani/dcdc501c55aac1ed145b2dbd7a15aa9f to your computer and use it in GitHub Desktop.
<?php
/**
کد زیر رو به فایل
functions.php
قالبتون اضافه کنید:
**/
/**
* Add calculator Shortcode
*/
add_action( 'init', 'ywp_add_calc_shortcode' );
function ywp_add_calc_shortcode() {
add_shortcode( 'price-calc', 'ywp_calc_price_sc_callback' );
}
/**
* Shortcode callback
*/
function ywp_calc_price_sc_callback( $atts ) {
extract( shortcode_atts( array(
'price' => 1,
), $atts ) );
$return = '<div><input type="number" id="ywp-calc-width" oninput="calc_price()><input type="number" id="ywp-calc-height" oninput="calc_price()"><label id="ywp-calc-result"></label></div>';
$return .= '<script>
function calc_price() {
document.getElementById("ywp-calc-result").innerHTML = document.getElementById("ywp-calc-width").value * document.getElementById("ywp-calc-height") * ' . $price . ' + " تومان";
}
</script>';
return $return;
}
/**
نحوه استفاده: این کد کوتاه رو داخل هر برگه یا نوشته ای که نیاز دارید قرار بدید. فقط استایلهاش رو باید تغییر بدید:
**/
[price-calc price="15000"]
/** بجای 15000 باید قیمت رو قرار بدید **/
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment