Last active
May 10, 2021 17:18
-
-
Save hamidrezayazdani/dcdc501c55aac1ed145b2dbd7a15aa9f to your computer and use it in GitHub Desktop.
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 | |
/** | |
کد زیر رو به فایل | |
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