Last active
November 27, 2023 19:28
-
-
Save patric-boehner/b2b8f582788c6576f15a15d665cdabb5 to your computer and use it in GitHub Desktop.
Set Gravity Forms price field value based on custom field
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 | |
// Set product price if dyncialy populate vlaue is set to 'workshop_price' | |
add_filter( 'gform_field_value_workshop_price', 'cf_custom_product_price', 10, 2 ); | |
function cf_custom_product_price( $value, $field ) { | |
global $post; | |
// Get the workshop price | |
$quantity = get_post_meta( $post->ID, 'workshop_price', true ); | |
// Default value | |
$quantity_value = ''; | |
// Check if set | |
if ( ! empty( $quantity ) && $field->type === 'product' ) { | |
$quantity_value = esc_attr( $quantity ); | |
} | |
return $quantity_value; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment