/** * Register term fields */ add_action( 'init', 'register_attributes_url_meta' ); function register_attributes_url_meta() { $attributes = wc_get_attribute_taxonomies(); foreach ( $attributes as $tax ) { $name = wc_attribute_taxonomy_name( $tax->attribute_name ); add_action( $name . '_add_form_fields', 'add_attribute_url_meta_field' ); add_action( $name . '_edit_form_fields', 'edit_attribute_url_meta_field', 10 ); add_action( 'edit_' . $name, 'save_attribute_url' ); add_action( 'create_' . $name, 'save_attribute_url' ); } } /** * Add term fields form */ function add_attribute_url_meta_field() { wp_nonce_field( basename( __FILE__ ), 'attrbute_url_meta_nonce' ); ?>
term_id, 'attribute_url', true ); wp_nonce_field( basename( __FILE__ ), 'attrbute_url_meta_nonce' ); ?> term_id, 'attribute_url', true ); if ( ! empty( $url ) ) { $val = '' . $value . ''; array_push( $new_values, $val ); } else { array_push( $new_values, $value ); } } else { $matched = preg_match_all( "/\[([^\]]+)\]\(([^)]+)\)/", $value, $matches ); if ( $matched && count( $matches ) == 3 ) { $val = '' . sanitize_text_field( $matches[1][0] ) . ''; array_push( $new_values, $val ); } else { array_push( $new_values, $value ); } } } $text = implode( ', ', $new_values ); return $text; }