Skip to content

Instantly share code, notes, and snippets.

@patric-boehner
Last active November 27, 2023 19:28
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save patric-boehner/b2b8f582788c6576f15a15d665cdabb5 to your computer and use it in GitHub Desktop.
Save patric-boehner/b2b8f582788c6576f15a15d665cdabb5 to your computer and use it in GitHub Desktop.
Set Gravity Forms price field value based on custom field
<?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