Created
August 20, 2025 12:02
-
-
Save plugin-republic/036cc1fdbba4602d6448b01de2d46669 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 | |
/** | |
* Add a custom parameter to add-on field settings | |
*/ | |
function demo_add_class_parameter( $group_key, $item_key, $item, $post_id ) { | |
echo '<div class="pewc-fields-wrapper pewc-my-new-fields">'; | |
echo '<div class="product-extra-field-third">'; | |
$class = isset( $item['class'] ) ? $item['class'] : ''; | |
echo '<label>Class</label>'; | |
echo '<input type="text" class="pewc-field-class" name="_product_extra_groups_' .esc_attr( $group_key ) . '_' . esc_attr( $item_key ) . '[class]" value="'. esc_html( $class ).'">'; | |
echo '</div>'; | |
echo '</div>'; | |
} | |
add_action( 'pewc_end_product_extra_field', 'demo_add_class_parameter', 10, 4 ); | |
/** | |
* Register the custom param to field data | |
*/ | |
function demo_register_class_parameter( $params, $field_id ) { | |
$params[] = 'class'; | |
return $params; | |
} | |
add_filter( 'pewc_item_params', 'demo_register_class_parameter', 10, 2 ); | |
/** | |
* Filter field classes | |
*/ | |
function demo_add_class_to_field_wrapper( $classes, $item ) { | |
if( ! empty( $item['class'] ) ) { | |
$classes[] = esc_attr( $item['class'] ); | |
} | |
return $classes; | |
} | |
add_filter( 'pewc_filter_single_product_classes', 'demo_add_class_to_field_wrapper', 10, 2 ); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment