Created
June 10, 2024 08:50
-
-
Save kkarpieszuk/917e335dc99a31ee5d669b1eedc61e95 to your computer and use it in GitHub Desktop.
This file contains hidden or 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 | |
/* | |
Display raw payment field amount with smart tag. | |
Usage: | |
- add code below to functions.php of your theme | |
- use smart tag `{field_amount="x"}` where x is the field ID from which you want to retrive raw amount without currency symbol etc. | |
*/ | |
add_filter( 'wpforms_smarttags_get_smart_tag_class_name', 'get_amount_class_name', 10, 1 ); | |
function get_amount_class_name( $class_name ) { | |
if ( 'field_amount' === $class_name ) { | |
return 'My_Amount_Smart_Tag'; | |
} | |
} | |
add_filter( 'wpforms_smart_tags', 'add_custom_smart_tag', 10, 1 ); | |
function add_custom_smart_tag( $tags ) { | |
$tags['field_amount'] = "Field raw amount"; | |
return $tags; | |
} | |
add_filter( 'wpforms_pro_smarttags_get_smart_tag_class_name', 'get_smart_tag_class_name', 10, 2 ); | |
function get_smart_tag_class_name( $class_name, $smart_tag_name ) { | |
if ( 'field_amount' === $smart_tag_name ) { | |
return 'My_Amount_Smart_Tag'; | |
} | |
return $class_name; | |
} | |
add_action( 'wpforms_loaded', function() { | |
class My_Amount_Smart_Tag extends WPForms\SmartTags\SmartTag\SmartTag { | |
public function get_value( $form_data, $fields = [], $entry_id = '' ) { | |
$attributes = $this->get_attributes(); | |
if ( ! isset( $attributes['field_amount'] ) || $attributes['field_amount'] === '' ) { | |
return ''; | |
} | |
return isset( $fields[ $attributes['field_amount'] ]['amount'] ) ? $fields[ $attributes['field_amount'] ]['amount'] : ''; | |
} | |
} | |
} | |
); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment